File indexing completed on 2024-10-08 05:11:51
0001
0002
0003
0004 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCProcessRPCSimDigis.h"
0005 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCLinkBoardGLSignal.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "GeometryConstants.h"
0008
0009
0010
0011
0012
0013
0014 using namespace rpctechnicaltrigger;
0015
0016 RBCProcessRPCSimDigis::RBCProcessRPCSimDigis(const edm::ESHandle<RPCGeometry>& rpcGeom,
0017 const edm::Handle<edm::DetSetVector<RPCDigiSimLink> >& digiSimLink) {
0018 m_ptr_rpcGeom = &rpcGeom;
0019 m_ptr_digiSimLink = &digiSimLink;
0020
0021 m_lbin = std::make_unique<RBCLinkBoardGLSignal>(&m_data);
0022
0023 m_debug = false;
0024 m_maxBxWindow = 3;
0025 }
0026
0027
0028
0029
0030 RBCProcessRPCSimDigis::~RBCProcessRPCSimDigis() { reset(); }
0031
0032
0033 int RBCProcessRPCSimDigis::next() {
0034
0035
0036 reset();
0037
0038 int ndigis(0);
0039
0040 for (m_linkItr = (*m_ptr_digiSimLink)->begin(); m_linkItr != (*m_ptr_digiSimLink)->end(); ++m_linkItr) {
0041 for (m_digiItr = m_linkItr->data.begin(); m_digiItr != m_linkItr->data.end(); ++m_digiItr) {
0042 if (m_debug)
0043 std::cout << "looping over digis 1 ..." << std::endl;
0044
0045 int bx = (*m_digiItr).getBx();
0046
0047 if (abs(bx) >= m_maxBxWindow) {
0048 if (m_debug)
0049 std::cout << "RBCProcessRPCSimDigis> found a bx bigger than max allowed: " << bx << std::endl;
0050 continue;
0051 }
0052
0053 uint32_t detid = m_digiItr->getDetUnitId();
0054 const RPCDetId id(detid);
0055 const RPCRoll* roll = dynamic_cast<const RPCRoll*>((*m_ptr_rpcGeom)->roll(id));
0056
0057 if ((roll->isForward())) {
0058 if (m_debug)
0059 std::cout << "RBCProcessRPCSimDigis: roll is forward" << std::endl;
0060 continue;
0061 }
0062
0063 int wheel = roll->id().ring();
0064 int sector = roll->id().sector();
0065 int layer = roll->id().layer();
0066 int station = roll->id().station();
0067 int blayer = getBarrelLayer(layer, station);
0068 int rollid = id.roll();
0069
0070 int digipos = (station * 100) + (layer * 10) + rollid;
0071
0072 if ((wheel == -1 || wheel == 0 || wheel == 1) && station == 2 && layer == 1)
0073 digipos = 30000 + digipos;
0074 if ((wheel == -2 || wheel == 2) && station == 2 && layer == 2)
0075 digipos = 30000 + digipos;
0076
0077 if ((wheel == -1 || wheel == 0 || wheel == 1) && station == 2 && layer == 2)
0078 digipos = 20000 + digipos;
0079 if ((wheel == -2 || wheel == 2) && station == 2 && layer == 1)
0080 digipos = 20000 + digipos;
0081
0082 if (m_debug)
0083 std::cout << "Bx: " << bx << '\t' << "Wheel: " << wheel << '\t' << "Sector: " << sector << '\t'
0084 << "Station: " << station << '\t' << "Layer: " << layer << '\t' << "B-Layer: " << blayer << '\t'
0085 << "Roll id: " << rollid << '\t' << "Digi at: " << digipos << '\n';
0086
0087
0088 auto itr = m_vecDataperBx.find(bx);
0089
0090 if (itr == m_vecDataperBx.end()) {
0091 if (m_debug)
0092 std::cout << "Found a new Bx: " << bx << std::endl;
0093 auto& wheelData = m_vecDataperBx[bx];
0094 initialize(wheelData);
0095 auto& block = wheelData[(wheel + 2)];
0096 setDigiAt(sector, digipos, block);
0097 } else {
0098 auto& block = (*itr).second[(wheel + 2)];
0099 setDigiAt(sector, digipos, block);
0100 }
0101
0102 if (m_debug)
0103 std::cout << "looping over digis 2 ..." << std::endl;
0104
0105 ++ndigis;
0106 }
0107 }
0108
0109 if (m_debug)
0110 std::cout << "size of data vectors: " << m_vecDataperBx.size() << std::endl;
0111
0112 builddata();
0113
0114 if (m_debug) {
0115 std::cout << "after reset" << std::endl;
0116 print_output();
0117 }
0118
0119 if (m_debug)
0120 std::cout << "RBCProcessRPCSimDigis: DataSize: " << m_data.size() << " ndigis " << ndigis << std::endl;
0121
0122 if (m_data.empty())
0123 return 0;
0124
0125 return 1;
0126 }
0127
0128 void RBCProcessRPCSimDigis::reset() { m_vecDataperBx.clear(); }
0129
0130 void RBCProcessRPCSimDigis::initialize(std::vector<RPCData>& dataVec) {
0131 if (m_debug)
0132 std::cout << "initialize" << std::endl;
0133
0134 constexpr int maxWheels = 5;
0135 constexpr int maxRbcBrds = 6;
0136
0137 dataVec.reserve(maxWheels);
0138 for (int i = 0; i < maxWheels; ++i) {
0139 auto& block = dataVec.emplace_back();
0140
0141 block.m_wheel = s_wheelid[i];
0142
0143 for (int j = 0; j < maxRbcBrds; ++j) {
0144 block.m_sec1[j] = s_sec1id[j];
0145 block.m_sec2[j] = s_sec2id[j];
0146 block.m_orsignals[j].input_sec[0].reset();
0147 block.m_orsignals[j].input_sec[1].reset();
0148 block.m_orsignals[j].needmapping = false;
0149 block.m_orsignals[j].hasData = false;
0150 }
0151 }
0152
0153 if (m_debug)
0154 std::cout << "initialize: completed" << std::endl;
0155 }
0156
0157 void RBCProcessRPCSimDigis::builddata() {
0158 int code(0);
0159
0160 for (auto& dataPerBx : m_vecDataperBx) {
0161 int bx = dataPerBx.first;
0162
0163 int bxsign;
0164 if (bx != 0)
0165 bxsign = (bx / abs(bx));
0166 else
0167 bxsign = 1;
0168
0169 for (auto& item : dataPerBx.second) {
0170 for (int k = 0; k < 6; ++k) {
0171 code = bxsign * (1000000 * abs(bx) + 10000 * item.wheelIdx() + 100 * item.m_sec1[k] + 1 * item.m_sec2[k]);
0172
0173 RBCInput* signal = &item.m_orsignals[k];
0174 signal->needmapping = false;
0175
0176 if (signal->hasData)
0177 m_data.insert(std::make_pair(code, signal));
0178 }
0179 }
0180 }
0181
0182 if (m_debug and not m_vecDataperBx.empty())
0183 std::cout << "builddata: completed. size of data: " << m_data.size() << std::endl;
0184 }
0185
0186 int RBCProcessRPCSimDigis::getBarrelLayer(const int& _layer, const int& _station) {
0187
0188 int blayer(0);
0189
0190 if (_station < 3) {
0191 blayer = ((_station - 1) * 2) + _layer;
0192 } else {
0193 blayer = _station + 2;
0194 }
0195
0196 return blayer;
0197 }
0198
0199 void RBCProcessRPCSimDigis::setDigiAt(int sector, int digipos, RPCData& block) {
0200 int pos = 0;
0201 int isAoB = 0;
0202
0203 if (m_debug)
0204 std::cout << "setDigiAt" << std::endl;
0205
0206 auto itr = std::find(s_sec1id.begin(), s_sec1id.end(), sector);
0207
0208 if (itr == s_sec1id.end()) {
0209 isAoB = 1;
0210 }
0211
0212 for (pos = 0; pos < 6; ++pos) {
0213 if (block.m_sec1[pos] == sector || block.m_sec2[pos] == sector)
0214 break;
0215 }
0216
0217 if (m_debug)
0218 std::cout << block.m_orsignals[pos];
0219
0220 setInputBit(block.m_orsignals[pos].input_sec[isAoB], digipos);
0221
0222 block.m_orsignals[pos].hasData = true;
0223
0224 if (m_debug)
0225 std::cout << block.m_orsignals[pos];
0226
0227 if (m_debug)
0228 std::cout << "setDigiAt completed" << std::endl;
0229 }
0230
0231 void RBCProcessRPCSimDigis::setInputBit(std::bitset<15>& signals, int digipos) {
0232 int bitpos = s_layermap.at(digipos);
0233 if (m_debug)
0234 std::cout << "Bitpos: " << bitpos << std::endl;
0235 signals.set(bitpos, true);
0236 }
0237
0238 void RBCProcessRPCSimDigis::print_output() {
0239 std::cout << "RBCProcessRPCSimDigis> Output starts" << std::endl;
0240
0241 std::map<int, RBCInput*>::const_iterator itr;
0242 for (itr = m_data.begin(); itr != m_data.end(); ++itr) {
0243 std::cout << (*itr).first << '\t' << (*(*itr).second) << '\n';
0244 }
0245
0246 std::cout << "RBCProcessRPCSimDigis> Output ends" << std::endl;
0247 }