File indexing completed on 2024-04-06 12:21:39
0001
0002 #include <array>
0003
0004
0005 #include "L1Trigger/RPCTechnicalTrigger/interface/RPCWheel.h"
0006 #include "GeometryConstants.h"
0007
0008
0009
0010
0011
0012 using namespace rpctechnicaltrigger;
0013
0014
0015
0016
0017 RPCWheel::RPCWheel() : m_id{0}, m_debug{false} {}
0018
0019 void RPCWheel::setProperties(int wid) {
0020 m_id = wid;
0021
0022 int bisector[2];
0023
0024 m_RBCE.reserve(m_maxrbc);
0025 for (int k = 0; k < m_maxrbc; ++k) {
0026 bisector[0] = s_sec1id[k];
0027 bisector[1] = s_sec2id[k];
0028 m_RBCE.emplace_back(std::make_unique<RBCEmulator>());
0029 m_RBCE[k]->setid(wid, bisector);
0030 }
0031
0032 for (int k = 0; k < m_maxsectors; ++k)
0033 m_wheelmap[k].reset();
0034 }
0035
0036 void RPCWheel::setProperties(int wid, const char* logic_type) {
0037 m_id = wid;
0038
0039 int bisector[2];
0040 m_RBCE.reserve(m_maxrbc);
0041 for (int k = 0; k < m_maxrbc; ++k) {
0042 bisector[0] = s_sec1id[k];
0043 bisector[1] = s_sec2id[k];
0044 m_RBCE.push_back(std::make_unique<RBCEmulator>(logic_type));
0045 m_RBCE[k]->setid(wid, bisector);
0046 }
0047
0048 for (int k = 0; k < m_maxsectors; ++k)
0049 m_wheelmap[k].reset();
0050 }
0051
0052 void RPCWheel::setProperties(int wid, const char* f_name, const char* logic_type) {
0053 m_id = wid;
0054
0055 int bisector[2];
0056
0057 m_RBCE.reserve(m_maxrbc);
0058 for (int k = 0; k < m_maxrbc; ++k) {
0059 bisector[0] = (k * 2) + 1;
0060 bisector[1] = (k * 2) + 2;
0061 m_RBCE.push_back(std::make_unique<RBCEmulator>(f_name, logic_type));
0062 m_RBCE[k]->setid(wid, bisector);
0063 }
0064
0065 for (int k = 0; k < m_maxsectors; ++k)
0066 m_wheelmap[k].reset();
0067 }
0068
0069
0070 void RPCWheel::setSpecifications(const RBCBoardSpecs* rbcspecs) {
0071 for (int k = 0; k < m_maxrbc; ++k)
0072 m_RBCE[k]->setSpecifications(rbcspecs);
0073 }
0074
0075 bool RPCWheel::initialise() {
0076 bool status(false);
0077 for (int k = 0; k < m_maxrbc; ++k)
0078 status = m_RBCE[k]->initialise();
0079 return status;
0080 }
0081
0082 void RPCWheel::emulate() {
0083
0084 for (int k = 0; k < m_maxrbc; ++k) {
0085 m_RBCE[k]->emulate();
0086 }
0087 }
0088
0089 bool RPCWheel::process(int bx, const std::map<int, RBCInput*>& data) {
0090 int bxsign(1);
0091 bool status(false);
0092
0093 std::map<int, RBCInput*>::const_iterator itr;
0094
0095 if (bx != 0)
0096 bxsign = (bx / abs(bx));
0097 else
0098 bxsign = 1;
0099
0100 for (int k = 0; k < m_maxrbc; ++k) {
0101 m_RBCE[k]->reset();
0102
0103 int key = bxsign * (1000000 * abs(bx) + m_RBCE[k]->rbcinfo().wheelIdx() * 10000 +
0104 m_RBCE[k]->rbcinfo().sector(0) * 100 + m_RBCE[k]->rbcinfo().sector(1));
0105
0106 itr = data.find(key);
0107
0108 if (itr != data.end()) {
0109 if (!(*itr).second->hasData) {
0110 status |= false;
0111 continue;
0112 } else {
0113 if (m_debug)
0114 std::cout << "RPCWheel::process> found data at: " << key << '\t' << (itr->second) << std::endl;
0115 m_RBCE[k]->emulate((itr->second));
0116 status |= true;
0117 }
0118
0119 } else {
0120
0121 status |= false;
0122 }
0123 }
0124
0125 return status;
0126 }
0127
0128 bool RPCWheel::process(int bx, const std::map<int, TTUInput*>& data) {
0129 int bxsign(1);
0130 bool status(false);
0131
0132 std::map<int, TTUInput*>::const_iterator itr;
0133
0134 if (bx != 0)
0135 bxsign = (bx / abs(bx));
0136 else
0137 bxsign = 1;
0138
0139 int key = bxsign * (1000000 * abs(bx) + (m_id + 2) * 10000);
0140
0141 itr = data.find(key);
0142
0143 if (itr != data.end()) {
0144 if (m_debug)
0145 std::cout << "RPCWheel::process> found data at: " << key << '\t' << (itr->second) << std::endl;
0146
0147 if (!(*itr).second->m_hasHits)
0148 return false;
0149
0150 for (int k = 0; k < m_maxsectors; ++k) {
0151 m_wheelmap[k] = (*itr).second->input_sec[k];
0152 status = true;
0153 }
0154
0155 } else {
0156
0157 status = false;
0158 }
0159
0160 return status;
0161 }
0162
0163
0164
0165 void RPCWheel::createWheelMap() {
0166 m_rbcDecision.reset();
0167
0168 std::bitset<6> layersignal;
0169
0170 layersignal = *m_RBCE[0]->getlayersignal(0);
0171 m_wheelmap[11] = layersignal;
0172
0173 m_rbcDecision.set(11, m_RBCE[0]->getdecision(0));
0174
0175 for (int k = 0; k < (m_maxrbc - 1); ++k) {
0176 layersignal = *m_RBCE[k + 1]->getlayersignal(0);
0177 m_wheelmap[(k * 2) + 1] = layersignal;
0178 layersignal = *m_RBCE[k + 1]->getlayersignal(1);
0179 m_wheelmap[(k * 2) + 2] = layersignal;
0180
0181 m_rbcDecision.set((k * 2) + 1, m_RBCE[k + 1]->getdecision(0));
0182 m_rbcDecision.set((k * 2) + 2, m_RBCE[k + 1]->getdecision(1));
0183 }
0184
0185 layersignal = *m_RBCE[0]->getlayersignal(1);
0186 m_wheelmap[0] = layersignal;
0187
0188 m_rbcDecision.set(0, m_RBCE[0]->getdecision(1));
0189
0190 if (m_debug)
0191 std::cout << "RPCWheel::createWheelMap done" << std::endl;
0192 }
0193
0194 void RPCWheel::retrieveWheelMap(TTUInput& output) {
0195 if (m_debug)
0196 std::cout << "RPCWheel::retrieveWheelMap starts" << std::endl;
0197 output.reset();
0198
0199 for (int i = 0; i < m_maxsectors; ++i) {
0200 for (int j = 0; j < m_maxlayers; ++j) {
0201 output.input_sec[i].set(j, m_wheelmap[i][j]);
0202 }
0203 }
0204
0205 output.m_wheelId = m_id;
0206
0207 output.m_rbcDecision = m_rbcDecision;
0208
0209 if (m_debug)
0210 print_wheel(output);
0211 if (m_debug)
0212 std::cout << "RPCWheel::retrieveWheelMap done" << std::endl;
0213 }
0214
0215
0216
0217 void RPCWheel::printinfo() const {
0218 std::cout << "Wheel -> " << m_id << '\n';
0219 for (int k = 0; k < m_maxrbc; ++k)
0220 m_RBCE[k]->printinfo();
0221 }
0222
0223 void RPCWheel::print_wheel(const TTUInput& wmap) const {
0224 std::cout << "RPCWheel::print_wheel> " << wmap.m_wheelId << '\t' << wmap.m_bx << std::endl;
0225
0226 for (int i = 0; i < m_maxsectors; ++i)
0227 std::cout << '\t' << (i + 1);
0228 std::cout << std::endl;
0229
0230 for (int k = 0; k < m_maxlayers; ++k) {
0231 std::cout << (k + 1) << '\t';
0232 for (int j = 0; j < m_maxsectors; ++j)
0233 std::cout << wmap.input_sec[j][k] << '\t';
0234 std::cout << std::endl;
0235 }
0236 }
0237
0238