7#define BOOST_BIND_GLOBAL_PLACEHOLDERS
8#include <boost/property_tree/json_parser.hpp>
20 size_t outerIndex = 0;
21 for (
const boost::property_tree::ptree::value_type& outer_elem :
node){
23 std::vector<float> buff(outer_elem.second.size());
25 for (
const boost::property_tree::ptree::value_type& inner_elem : outer_elem.second) {
26 buff[
index] = inner_elem.second.get_value<
float>();
30 if (outer_elem.first.length() > 0) {
31 theLut[std::stoi(outer_elem.first)] = std::move(buff);
33 theLut[outerIndex] = std::move(buff);
40 void L1TopoLUT::fillFromPtree(
const boost::property_tree::ptree&
node, std::map<
unsigned short,std::map<
unsigned short, std::pair<unsigned short, unsigned short>>>& theLut)
const
43 for (
const boost::property_tree::ptree::value_type& outer_elem :
node){
45 std::map<unsigned short,std::pair<unsigned short, unsigned short>> buff;
46 for (
const boost::property_tree::ptree::value_type& inner_elem : outer_elem.second) {
47 std::vector<unsigned short> codeBuff;
48 for (
const boost::property_tree::ptree::value_type& code_elem : inner_elem.second) {
49 codeBuff.push_back( code_elem.second.get_value<
unsigned short>() );
51 if ( codeBuff.size() != 2 ) {
55 buff[std::stoi(inner_elem.first)] = { codeBuff[0], codeBuff[1] } ;
58 theLut[std::stoi(outer_elem.first)] = std::move(buff);
65 const std::string& side1LUTFileName) {
67 boost::property_tree::ptree root0;
68 boost::property_tree::read_json(side0LUTFileName.c_str(), root0);
69 boost::property_tree::ptree root1;
70 boost::property_tree::read_json(side1LUTFileName.c_str(), root1);
106 const std::string& ecfFileName,
107 const std::string& side0LUTFileName,
108 const std::string& side1LUTFileName) {
134 std::unordered_map<L1TopoLUTKey, std::map<float, unsigned short>,
L1TopoLUTKeyHasher> sector_eta_indices, sector_phi_indices;
136 std::ifstream inFile(inFileName.c_str());
137 if (!inFile)
return false;
138 while (!inFile.eof() && inFile.good()) {
140 unsigned short subsystem=0;
141 unsigned short sectorID;
143 double eta_min, eta_max;
144 double phi_min, phi_max;
147 if (inFile.eof()) {
break; }
171 unsigned short ieta = 0;
172 unsigned short iphi = 0;
173 if (subsystem == 0) {
177 }
else if (subsystem == 1) {
181 iphi |= (sectorID & 0x3F) << 2;
182 }
else if (subsystem == 2) {
185 iphi = (roi & 0x3) << 1;
186 iphi |= (sectorID & 0x1F) << 3;
192 if (subsystem == 0) {
194 unsigned short etaPhiSubWord = ((ieta&0xF) << 9) | ((sectorID&0x1F) << 3) | (iphi&0x7);
214 m_errors.push_back(
"Duplicate key found in L1TopoLUT: "+key.info());
224 const unsigned short& subsystem,
225 const unsigned short& sectorID,
226 const unsigned short& roi)
const {
237 unsigned short L1TopoLUT::getBarrelROI(
unsigned short side,
unsigned short sector,
unsigned short ieta,
unsigned short iphi)
const {
238 unsigned short etaPhiSubWord = ((ieta&0xF) << 9) | ((sector&0x1F) << 3) | (iphi&0x7);
239 unsigned short retval = 0;
253 float retval = std::numeric_limits<float>::quiet_NaN();
255 if (subsystem == 0) {
259 }
else if (subsystem == 1) {
261 }
else if (subsystem == 2) {
264 std::stringstream ess;
265 ess <<
"[TrigT1MuctpiPhase1/L1TopoLUT] Unknown muon subsystem value: " << subsystem;
266 throw std::out_of_range(ess.str());
268 }
catch (
const std::exception& e) {
269 std::stringstream ess;
270 ess <<
"[TrigT1MuctpiPhase1/L1TopoLUT] Failed to look up eta value for subsystem=" << subsystem
271 <<
", side="<< (side?
"A":
"C")
272 <<
", sectorID="<< sectorID
274 <<
"\n (caught exception: " << e.what() <<
")";
275 throw std::out_of_range(ess.str());
284 float retval = std::numeric_limits<float>::quiet_NaN();
286 if (subsystem == 0) {
290 }
else if (subsystem == 1) {
292 }
else if (subsystem == 2) {
295 std::stringstream ess;
296 ess <<
"[TrigT1MuctpiPhase1/L1TopoLUT] Unknown muon subsystem value: " << subsystem;
297 throw std::out_of_range(ess.str());
299 }
catch (
const std::exception& e) {
300 std::stringstream ess;
301 ess <<
"[TrigT1MuctpiPhase1/L1TopoLUT] Failed to look up phi value for subsystem=" << subsystem
302 <<
", side="<< (side?
"A":
"C")
303 <<
", sectorID="<< sectorID
305 <<
"\n (caught exception: " << e.what() <<
")";
306 throw std::out_of_range(ess.str());
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
unsigned short getBarrelROI(unsigned short side, unsigned short sector, unsigned short ieta, unsigned short iphi) const
std::map< unsigned short, std::vector< float > > m_forward_eta_lookup1
float getCompactedValue_phi(unsigned short subsystem, unsigned short side, unsigned short sectorID, unsigned short roi)
bool initializeCompactedLUTs(const std::string &side0LUTFileName, const std::string &side1LUTFileName)
std::map< unsigned short, std::vector< float > > m_forward_phi_lookup0
std::map< unsigned short, std::vector< float > > m_barrel_phi_lookup0
std::map< unsigned short, unsigned short > m_barrel_reverse_encoding0
std::vector< std::string > m_errors
std::map< unsigned short, std::vector< float > > m_barrel_eta_lookup0
std::unordered_map< L1TopoLUTKey, L1TopoCoordinates, L1TopoLUTKeyHasher > m_encoding
std::map< unsigned short, std::vector< float > > m_endcap_eta_lookup0
std::map< unsigned short, std::vector< float > > m_barrel_phi_lookup1
std::map< unsigned short, std::vector< float > > m_endcap_eta_lookup1
L1TopoCoordinates getCoordinates(const unsigned short &side, const unsigned short &subsystem, const unsigned short §orID, const unsigned short &roi) const
std::map< unsigned short, unsigned short > m_barrel_reverse_encoding1
std::map< unsigned short, std::vector< float > > m_forward_eta_lookup0
std::map< unsigned short, std::vector< float > > m_endcap_phi_lookup0
void fillFromPtree(const boost::property_tree::ptree &node, std::map< unsigned short, std::vector< float > > &theLut) const
float getCompactedValue_eta(unsigned short subsystem, unsigned short side, unsigned short sectorID, unsigned short roi)
std::map< unsigned short, std::map< unsigned short, std::pair< unsigned short, unsigned short > > > m_barrel_encoding1
std::map< unsigned short, std::vector< float > > m_forward_phi_lookup1
bool initializeLUT(const std::string &barrelFileName, const std::string &ecfFileName, const std::string &side0LUTFileName, const std::string &side1LUTFileName)
std::map< unsigned short, std::map< unsigned short, std::pair< unsigned short, unsigned short > > > m_barrel_encoding0
std::map< unsigned short, std::vector< float > > m_endcap_phi_lookup1
std::map< unsigned short, std::vector< float > > m_barrel_eta_lookup1