Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:34

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