CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/L1Trigger/RPCTrigger/src/RPCConeBuilderFromES.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     RPCTrigger
00004 // Class  :     RPCConeBuilderFromES
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  
00010 //         Created:  Mon Mar  3 13:34:20 CET 2008
00011 // $Id: RPCConeBuilderFromES.cc,v 1.11 2011/02/25 16:56:18 fruboes Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "L1Trigger/RPCTrigger/interface/RPCConeBuilderFromES.h"
00018 
00019 
00020 //
00021 // constants, enums and typedefs
00022 //
00023 
00024 //
00025 // static data member definitions
00026 //
00027 
00028 //
00029 // constructors and destructor
00030 //
00031 RPCConeBuilderFromES::RPCConeBuilderFromES()
00032 {
00033 }
00034 
00035 // RPCConeBuilderFromES::RPCConeBuilderFromES(const RPCConeBuilderFromES& rhs)
00036 // {
00037 //    // do actual copying here;
00038 // }
00039 
00040 RPCConeBuilderFromES::~RPCConeBuilderFromES()
00041 {
00042 }
00043 
00044 L1RpcLogConesVec RPCConeBuilderFromES::getConesFromES(edm::Handle<RPCDigiCollection> rpcDigis, 
00045                                                       edm::ESHandle<L1RPCConeBuilder> coneBuilder,
00046                                                       edm::ESHandle<L1RPCConeDefinition> coneDef,
00047                                                       edm::ESHandle<L1RPCBxOrConfig> bxOrDef,
00048                                                       edm::ESHandle<L1RPCHwConfig> hwConfig, int bx)
00049 {
00050   std::vector<RPCLogHit> logHits;
00051   std::vector<RPCLogHit> logHitsFromUncomp;
00052   
00053   // Build cones from digis
00054   // first build loghits
00055 
00056   short int digiIndex = 0; 
00057   RPCDigiCollection::DigiRangeIterator detUnitIt;
00058   for (detUnitIt=rpcDigis->begin();
00059        detUnitIt!=rpcDigis->end();
00060        ++detUnitIt)
00061   {
00062     const RPCDetId& id = (*detUnitIt).first;
00063 
00064     uint32_t rawId = id.rawId();
00065 
00066     const RPCDigiCollection::Range& range = (*detUnitIt).second;
00067 
00068     std::pair<L1RPCConeBuilder::TCompressedConVec::const_iterator, L1RPCConeBuilder::TCompressedConVec::const_iterator> 
00069           compressedConnPair = coneBuilder->getCompConVec(rawId);
00070 
00071     // iterate over strips
00072     for (RPCDigiCollection::const_iterator digiIt = range.first;
00073          digiIt!=range.second;
00074          ++digiIt)
00075     {
00076       
00077       ++digiIndex;
00078       if ( digiIt->bx() < bxOrDef->getFirstBX() + bx || digiIt->bx() > bxOrDef->getLastBX() +bx  ){
00079       //if ( digiIt->bx() < hwConfig->getFirstBX() + bx || digiIt->bx() > hwConfig->getLastBX() +bx  ){
00080         continue;
00081       }
00082       
00083       //std::cout << digiIt->bx() << " D " << rawId << " " << id << " S " <<  digiIt->strip() << std::endl;
00084       // for uncompressed connections
00085       std::pair<L1RPCConeBuilder::TStripConVec::const_iterator, L1RPCConeBuilder::TStripConVec::const_iterator> 
00086           itPair = coneBuilder->getConVec(rawId,digiIt->strip());
00087 
00088       L1RPCConeBuilder::TStripConVec::const_iterator it = itPair.first;
00089       // Iterate over uncompressed connections, convert digis to logHits 
00090       for (; it!=itPair.second;++it){
00091          //std::cout << " Not empty!" << std::endl;
00092          if ( hwConfig->isActive(it->m_tower, it->m_PAC)  ){
00093 
00094              RPCLogHit lh(it->m_tower, it->m_PAC, it->m_logplane, it->m_logstrip); 
00095              lh.setDigiIdx(digiIndex);  
00096              logHitsFromUncomp.push_back( lh );
00097          } 
00098       }
00099 
00100       /*
00101       bool printOut = false;
00102       if (digiIt->strip() == 62 || digiIt->strip() == 63 ){
00103         std::cout << "Strip " << digiIt->strip() << std::endl;
00104         printOut = true;
00105       }
00106       */
00107       
00108       L1RPCConeBuilder::TCompressedConVec::const_iterator itComp = compressedConnPair.first;
00109       for (; itComp!=compressedConnPair.second; ++itComp){
00110          if ( hwConfig->isActive(itComp->m_tower, itComp->m_PAC)){
00111            int logstrip = itComp->getLogStrip(digiIt->strip(),coneDef->getLPSizeVec());
00112            if (logstrip!=-1){
00113                RPCLogHit lh(itComp->m_tower, itComp->m_PAC, itComp->m_logplane, logstrip );
00114                lh.setDigiIdx(digiIndex);
00115                logHits.push_back( lh );
00116            }
00117            /*
00118            if (printOut){
00119              std::cout << "T " << (int)itComp->m_tower << " P " 
00120                  << (int)itComp->m_PAC << " LP " 
00121                  << (int)itComp->m_logplane << " LS " 
00122                  << (int)logstrip << std::endl;
00123          }*/
00124            
00125          }
00126       }
00127 
00128     } // strip iteration ends
00129     
00130   }
00131   
00132 
00133   // check if we dont have any preferable uncompressed loghits
00134   std::vector<RPCLogHit>::iterator itLHitUncomp = logHitsFromUncomp.begin();
00135   std::vector<RPCLogHit>::iterator itLHitComp;
00136 
00137   // overwrite uncompressed with those coming from compressed
00138   for(;itLHitUncomp != logHitsFromUncomp.end(); ++itLHitUncomp) {
00139     for (itLHitComp = logHits.begin();  itLHitComp != logHits.end(); ++itLHitComp){
00140 
00141       if ( itLHitComp->getTower() == itLHitUncomp->getTower() 
00142            && itLHitComp->getLogSector() == itLHitUncomp->getLogSector()   
00143            && itLHitComp->getLogSegment() == itLHitUncomp->getLogSegment()   
00144            && itLHitComp->getlogPlaneNumber() == itLHitUncomp->getlogPlaneNumber()  )
00145       {
00146 //         std::cout<< "Overwrite " << std::endl;
00147         //std::cout.flush();
00148           *itLHitUncomp = *itLHitComp;
00149       } 
00150 
00151     }
00152   }
00153 
00154   // copy missing from compressed to uncompressed  
00155   for(;itLHitUncomp != logHitsFromUncomp.end(); ++itLHitUncomp) {
00156     bool present = false;
00157     for (unsigned int i=0;  i < logHits.size(); ++i)  
00158     {
00159 
00160       if ( logHits[i].getTower() == itLHitUncomp->getTower()
00161            && logHits[i].getLogSector() == itLHitUncomp->getLogSector()
00162            && logHits[i].getLogSegment() == itLHitUncomp->getLogSegment()
00163            && logHits[i].getlogPlaneNumber() == itLHitUncomp->getlogPlaneNumber()  )
00164       {
00165          present = true;
00166       }
00167     }
00168     if (!present)
00169     {
00170 //       std::cout<< "Copy " << std::endl;
00171       //std::cout.flush();
00172 
00173       logHits.push_back(*itLHitUncomp);
00174     }
00175   }
00176 
00177   // build cones
00178   L1RpcLogConesVec ActiveCones;
00179 
00180   std::vector<RPCLogHit>::iterator p_lhit;
00181   for (p_lhit = logHits.begin(); p_lhit != logHits.end(); ++p_lhit){
00182 
00183     bool hitTaken = false;
00184     L1RpcLogConesVec::iterator p_cone;
00185     for (p_cone = ActiveCones.begin(); p_cone != ActiveCones.end(); p_cone++){
00186       hitTaken = p_cone->addLogHit(*p_lhit);
00187       if(hitTaken)
00188         break;
00189     }
00190 
00191     if(!hitTaken) {
00192       RPCLogCone newcone(*p_lhit);
00193       newcone.setIdx(ActiveCones.size());
00194       ActiveCones.push_back(newcone);
00195     }
00196   }// for loghits
00197 
00198   /*
00199   for (int tower = -16; tower<17;++tower)
00200   {
00201     for (int sector = 0; sector<12;++sector)
00202     {
00203       for (int segment = 0; segment<12;++segment)
00204       {
00205         for (L1RpcLogConesVec::iterator it =  ActiveCones.begin(); it!=ActiveCones.end(); ++it)
00206         {
00207           if (it->getTower()==tower 
00208               && it->getLogSector()==sector
00209               && it->getLogSegment()==segment)
00210           {
00211            std::cout << it->toString() << std::endl;
00212           }
00213         }
00214       }
00215     }
00216   }
00217   // */
00218   
00219   return ActiveCones;
00220   
00221 }
00222