Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:     RPCTrigger
0004 // Class  :     RPCConeBuilderFromES
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Mon Mar  3 13:34:20 CET 2008
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "L1Trigger/RPCTrigger/interface/RPCConeBuilderFromES.h"
0017 
0018 //
0019 // constants, enums and typedefs
0020 //
0021 
0022 //
0023 // static data member definitions
0024 //
0025 
0026 //
0027 // constructors and destructor
0028 //
0029 RPCConeBuilderFromES::RPCConeBuilderFromES() {}
0030 
0031 // RPCConeBuilderFromES::RPCConeBuilderFromES(const RPCConeBuilderFromES& rhs)
0032 // {
0033 //    // do actual copying here;
0034 // }
0035 
0036 RPCConeBuilderFromES::~RPCConeBuilderFromES() {}
0037 
0038 L1RpcLogConesVec RPCConeBuilderFromES::getConesFromES(edm::Handle<RPCDigiCollection> rpcDigis,
0039                                                       edm::ESHandle<L1RPCConeBuilder> coneBuilder,
0040                                                       edm::ESHandle<L1RPCConeDefinition> coneDef,
0041                                                       edm::ESHandle<L1RPCBxOrConfig> bxOrDef,
0042                                                       edm::ESHandle<L1RPCHwConfig> hwConfig,
0043                                                       int bx) {
0044   std::vector<RPCLogHit> logHits;
0045   std::vector<RPCLogHit> logHitsFromUncomp;
0046 
0047   // Build cones from digis
0048   // first build loghits
0049 
0050   short int digiIndex = 0;
0051   RPCDigiCollection::DigiRangeIterator detUnitIt;
0052   for (detUnitIt = rpcDigis->begin(); detUnitIt != rpcDigis->end(); ++detUnitIt) {
0053     const RPCDetId& id = (*detUnitIt).first;
0054 
0055     uint32_t rawId = id.rawId();
0056 
0057     const RPCDigiCollection::Range& range = (*detUnitIt).second;
0058 
0059     std::pair<L1RPCConeBuilder::TCompressedConVec::const_iterator, L1RPCConeBuilder::TCompressedConVec::const_iterator>
0060         compressedConnPair = coneBuilder->getCompConVec(rawId);
0061 
0062     // iterate over strips
0063     for (RPCDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
0064       ++digiIndex;
0065       if (digiIt->bx() < bxOrDef->getFirstBX() + bx || digiIt->bx() > bxOrDef->getLastBX() + bx) {
0066         //if ( digiIt->bx() < hwConfig->getFirstBX() + bx || digiIt->bx() > hwConfig->getLastBX() +bx  ){
0067         continue;
0068       }
0069 
0070       //std::cout << digiIt->bx() << " D " << rawId << " " << id << " S " <<  digiIt->strip() << std::endl;
0071       // for uncompressed connections
0072       std::pair<L1RPCConeBuilder::TStripConVec::const_iterator, L1RPCConeBuilder::TStripConVec::const_iterator> itPair =
0073           coneBuilder->getConVec(rawId, digiIt->strip());
0074 
0075       L1RPCConeBuilder::TStripConVec::const_iterator it = itPair.first;
0076       // Iterate over uncompressed connections, convert digis to logHits
0077       for (; it != itPair.second; ++it) {
0078         //std::cout << " Not empty!" << std::endl;
0079         if (hwConfig->isActive(it->m_tower, it->m_PAC)) {
0080           RPCLogHit lh(it->m_tower, it->m_PAC, it->m_logplane, it->m_logstrip);
0081           lh.setDigiIdx(digiIndex);
0082           logHitsFromUncomp.push_back(lh);
0083         }
0084       }
0085 
0086       /*
0087       bool printOut = false;
0088       if (digiIt->strip() == 62 || digiIt->strip() == 63 ){
0089         std::cout << "Strip " << digiIt->strip() << std::endl;
0090         printOut = true;
0091       }
0092       */
0093 
0094       L1RPCConeBuilder::TCompressedConVec::const_iterator itComp = compressedConnPair.first;
0095       for (; itComp != compressedConnPair.second; ++itComp) {
0096         if (hwConfig->isActive(itComp->m_tower, itComp->m_PAC)) {
0097           int logstrip = itComp->getLogStrip(digiIt->strip(), coneDef->getLPSizeVec());
0098           if (logstrip != -1) {
0099             RPCLogHit lh(itComp->m_tower, itComp->m_PAC, itComp->m_logplane, logstrip);
0100             lh.setDigiIdx(digiIndex);
0101             logHits.push_back(lh);
0102           }
0103           /*
0104            if (printOut){
0105              std::cout << "T " << (int)itComp->m_tower << " P " 
0106                  << (int)itComp->m_PAC << " LP " 
0107                  << (int)itComp->m_logplane << " LS " 
0108                  << (int)logstrip << std::endl;
0109          }*/
0110         }
0111       }
0112 
0113     }  // strip iteration ends
0114   }
0115 
0116   // check if we dont have any preferable uncompressed loghits
0117   std::vector<RPCLogHit>::iterator itLHitUncomp = logHitsFromUncomp.begin();
0118   std::vector<RPCLogHit>::iterator itLHitComp;
0119 
0120   // overwrite uncompressed with those coming from compressed
0121   for (; itLHitUncomp != logHitsFromUncomp.end(); ++itLHitUncomp) {
0122     for (itLHitComp = logHits.begin(); itLHitComp != logHits.end(); ++itLHitComp) {
0123       if (itLHitComp->getTower() == itLHitUncomp->getTower() &&
0124           itLHitComp->getLogSector() == itLHitUncomp->getLogSector() &&
0125           itLHitComp->getLogSegment() == itLHitUncomp->getLogSegment() &&
0126           itLHitComp->getlogPlaneNumber() == itLHitUncomp->getlogPlaneNumber()) {
0127         //         std::cout<< "Overwrite " << std::endl;
0128         //std::cout.flush();
0129         *itLHitUncomp = *itLHitComp;
0130       }
0131     }
0132   }
0133 
0134   // copy missing from compressed to uncompressed
0135   for (; itLHitUncomp != logHitsFromUncomp.end(); ++itLHitUncomp) {
0136     bool present = false;
0137     for (unsigned int i = 0; i < logHits.size(); ++i) {
0138       if (logHits[i].getTower() == itLHitUncomp->getTower() &&
0139           logHits[i].getLogSector() == itLHitUncomp->getLogSector() &&
0140           logHits[i].getLogSegment() == itLHitUncomp->getLogSegment() &&
0141           logHits[i].getlogPlaneNumber() == itLHitUncomp->getlogPlaneNumber()) {
0142         present = true;
0143       }
0144     }
0145     if (!present) {
0146       //       std::cout<< "Copy " << std::endl;
0147       //std::cout.flush();
0148 
0149       logHits.push_back(*itLHitUncomp);
0150     }
0151   }
0152 
0153   // build cones
0154   L1RpcLogConesVec ActiveCones;
0155 
0156   std::vector<RPCLogHit>::iterator p_lhit;
0157   for (p_lhit = logHits.begin(); p_lhit != logHits.end(); ++p_lhit) {
0158     bool hitTaken = false;
0159     L1RpcLogConesVec::iterator p_cone;
0160     for (p_cone = ActiveCones.begin(); p_cone != ActiveCones.end(); p_cone++) {
0161       hitTaken = p_cone->addLogHit(*p_lhit);
0162       if (hitTaken)
0163         break;
0164     }
0165 
0166     if (!hitTaken) {
0167       RPCLogCone newcone(*p_lhit);
0168       newcone.setIdx(ActiveCones.size());
0169       ActiveCones.push_back(newcone);
0170     }
0171   }  // for loghits
0172 
0173   /*
0174   for (int tower = -16; tower<17;++tower)
0175   {
0176     for (int sector = 0; sector<12;++sector)
0177     {
0178       for (int segment = 0; segment<12;++segment)
0179       {
0180         for (L1RpcLogConesVec::iterator it =  ActiveCones.begin(); it!=ActiveCones.end(); ++it)
0181         {
0182           if (it->getTower()==tower 
0183               && it->getLogSector()==sector
0184               && it->getLogSegment()==segment)
0185           {
0186            std::cout << it->toString() << std::endl;
0187           }
0188         }
0189       }
0190     }
0191   }
0192   // */
0193 
0194   return ActiveCones;
0195 }