CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/L1Trigger/RPCTrigger/plugins/RPCConeBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    RPCConeBuilder
00004 // Class:      RPCConeBuilder
00005 // 
00013 //
00014 // Original Author:  Tomasz Maciej Frueboes
00015 //         Created:  Fri Feb 22 13:57:06 CET 2008
00016 // $Id: RPCConeBuilder.cc,v 1.3 2011/02/25 16:56:31 fruboes Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 
00023 // user include files
00024 
00025 #include "L1Trigger/RPCTrigger/interface/RPCConeBuilder.h"
00026 #include "L1Trigger/RPCTrigger/interface/RPCStripsRing.h"
00027 
00028 //#include "L1TriggerConfig/RPCConeBuilder/interface/RPCConeBuilder.h"
00029 //#include "L1TriggerConfig/RPCConeBuilder/interface/RPCStripsRing.h"
00030 
00031 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00032 #include "FWCore/Framework/interface/ModuleFactory.h"
00033 
00034 
00035 #include "CondFormats/DataRecord/interface/L1RPCConeDefinitionRcd.h"
00036 
00037 #include <sstream>
00038 #include <vector>
00039 
00040 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00041 
00042 
00043 RPCConeBuilder::RPCConeBuilder(const edm::ParameterSet& iConfig) :
00044       m_towerBeg(iConfig.getParameter<int>("towerBeg")),
00045       m_towerEnd(iConfig.getParameter<int>("towerEnd")),
00046       m_runOnceBuildCones(false)
00047       //m_rollBeg(iConfig.getParameter<int>("rollBeg")),
00048       //m_rollEnd(iConfig.getParameter<int>("rollEnd")),
00049       //m_hwPlaneBeg(iConfig.getParameter<int>("hwPlaneBeg")),
00050       //m_hwPlaneEnd(iConfig.getParameter<int>("hwPlaneEnd"))
00051 {
00052    
00053   setWhatProduced(this, (dependsOn (&RPCConeBuilder::geometryCallback) &  
00054                                    (&RPCConeBuilder::coneDefCallback)     )
00055                         );
00056 
00057   /* TT
00058    for (int i = m_towerBeg; i <= m_towerEnd; ++i){
00059       
00060       std::stringstream name;
00061       name << "lpSizeTower" << i;
00062       
00063       L1RPCConeBuilder::TLogPlaneSize newSizes = 
00064             iConfig.getParameter<std::vector<int> >(name.str().c_str());
00065       
00066       m_LPSizesInTowers.push_back(newSizes);
00067       
00068    }
00069   
00070   */
00071    
00072    //  hw planes numbered from 0 to 5
00073    // rolls from 0 to 17 (etaPartition)
00074    //
00075    //  rollConnLP_[roll]_[hwPlane-1]
00076    //  rollConnLP_5_3 = cms.vint32(6, 0, 0),
00077    //     ----- roll 5, hwPlane 4 (3+1) is logplane 6 (OK)
00078    //
00079    //  rollConnT_[roll]_[hwPlane-1]
00080    //  rollConnT_5_3 = cms.vint32(4, -1, -1),
00081    //     ----- roll 5, hwPlane 4 (3+1) contirubtes to tower 4 (OK)
00082   
00083   /*
00084    for (int roll = m_rollBeg; roll <= m_rollEnd; ++roll){
00085       L1RPCConeDefinition::THWplaneToTower newHwPlToTower;
00086       L1RPCConeDefinition::THWplaneToLP newHWplaneToLP;
00087       for (int hwpl = m_hwPlaneBeg; hwpl <= m_hwPlaneEnd; ++hwpl){
00088          std::stringstream name;
00089          name << "rollConnLP_" << roll << "_" << hwpl;
00090          
00091          L1RPCConeDefinition::TTowerList newListLP = 
00092                iConfig.getParameter<std::vector<int> >(name.str().c_str());
00093          newHWplaneToLP.push_back(newListLP);
00094          
00095          
00096          std::stringstream name1;
00097          name1 << "rollConnT_" << roll << "_" << hwpl;
00098          
00099          L1RPCConeDefinition::TLPList newListT = 
00100                iConfig.getParameter<std::vector<int> >(name1.str().c_str());
00101          newHwPlToTower.push_back(newListT);
00102       }
00103       m_RingsToTowers.push_back(newHwPlToTower);
00104       m_RingsToLP.push_back(newHWplaneToLP);
00105    }
00106   */
00107 }
00108 
00109 
00110 
00111 
00112 // 
00113 // member functions
00114 //
00115 
00116 // ------------ method called to produce the data  ------------
00117 RPCConeBuilder::ReturnType
00118 RPCConeBuilder::produce(const L1RPCConeBuilderRcd& iRecord)
00119 //RPCConeBuilder::produce(const L1RPCConfigRcd& iRecord)
00120 {
00121 
00122   
00123    //std::cout << " RPCConeBuilder::produce called " << std::endl;
00124    using namespace edm::es;
00125    boost::shared_ptr<L1RPCConeBuilder> pL1RPCConeBuilder( ( new L1RPCConeBuilder ) );
00126    
00127    pL1RPCConeBuilder->setFirstTower(m_towerBeg);
00128    pL1RPCConeBuilder->setLastTower(m_towerEnd);
00129    
00130    /*
00131    pL1RPCConeBuilder->setLPSizeForTowers(m_LPSizesInTowers);
00132    pL1RPCConeBuilder->setRingsToLP(m_RingsToLP);
00133    */
00134    
00135    //iRecord.get(m_rpcGeometry);
00136    //iRecord.get(m_L1RPCConeDefinition);
00137    buildCones(m_rpcGeometry);
00138 
00139    // Compress all connections. Since members of this class are shared
00140    // pointers this call will compress all data
00141    m_ringsMap.begin()->second.compressConnections();
00142       
00143    pL1RPCConeBuilder->setConeConnectionMap(m_ringsMap.begin()->second.getConnectionsMap());
00144    
00145    pL1RPCConeBuilder->setCompressedConeConnectionMap(
00146            m_ringsMap.begin()->second.getCompressedConnectionsMap());
00147            
00148    m_ringsMap.clear(); // free mem
00149       
00150    return pL1RPCConeBuilder;
00151    
00152 }
00153 
00154 // ----------------------------------------------------------
00155 void RPCConeBuilder::geometryCallback( const MuonGeometryRecord& record ){
00156 
00157   //std::cout << " Geometry callback called " << std::endl; 
00158   m_runOnceBuildCones = false; // allow re-running of buildCones
00159   record.get(m_rpcGeometry);
00160   
00161   
00162 }
00163 
00164 void RPCConeBuilder::coneDefCallback( const L1RPCConeDefinitionRcd& record ){
00165 
00166   //std::cout << " ConeDef callback called " << std::endl; 
00167   m_runOnceBuildCones = false; // allow re-running of buildCones
00168 
00169   //edm::ESHandle<RPCGeometry> rpcGeom;
00170   record.get(m_L1RPCConeDefinition);
00171   
00172   //std::cout << " ConeDef callback exit " << std::endl; 
00173   //std::cout.flush();
00174   //buildCones(rpcGeom);
00175   
00176 }
00177 
00178 
00179 
00180 void RPCConeBuilder::buildCones(const edm::ESHandle<RPCGeometry> & rpcGeom ){
00181   
00182 
00183   if (!m_runOnceBuildCones){
00184     m_runOnceBuildCones = true;
00185   } else {
00186     throw cms::Exception("RPCInternal") << "buildCones called twice \n";
00187   }
00188   
00189   //std::cout << "    ---> buildCones called " << std::endl; 
00190   
00191   // fetch geometricall data
00192   boost::shared_ptr<L1RPCConeBuilder::TConMap > uncompressedCons
00193         = boost::shared_ptr<L1RPCConeBuilder::TConMap >(new L1RPCConeBuilder::TConMap());
00194   
00195   
00196   int rolls = 0;
00197   for(TrackingGeometry::DetContainer::const_iterator it = rpcGeom->dets().begin();
00198       it != rpcGeom->dets().end();
00199       ++it)
00200   {
00201   
00202       if( dynamic_cast< RPCRoll* >( *it ) == 0 ) continue;
00203       
00204       ++rolls;
00205       RPCRoll* roll = dynamic_cast< RPCRoll*>( *it );
00206       
00207       int ringId = RPCStripsRing::getRingId(roll);
00208       if ( m_ringsMap.find(ringId)  == m_ringsMap.end() ) {
00209         m_ringsMap[ringId]=RPCStripsRing(roll, uncompressedCons);
00210       } else {
00211          m_ringsMap[ringId].addRoll(roll);
00212       }
00213       //RPCStripsRing sr(roll);
00214       
00215   }
00216 
00217   //std::cout << " found: " << rolls << " dets" << std::endl;
00218   
00219   RPCStripsRing::TIdToRindMap::iterator it = m_ringsMap.begin();
00220   
00221   // filtermixed strips, fill gaps with virtual strips
00222   for (;it != m_ringsMap.end(); ++it){
00223      
00224     //int before = it->second.size();
00225     
00226     it->second.filterOverlapingChambers();    
00227     it->second.fillWithVirtualStrips();
00228 
00229     
00230     //std::cout << it->first << " " <<  it->second.isReferenceRing() << " " 
00231      //   << before << " -> " 
00232       //  << it->second.size() << std::endl;
00233     
00234     // In reference plane we should have 144*8 = 1152 strips
00235     //int plane = it->first/1000;
00236     int etaPart =  it->first%100; 
00237     if (it->second.isReferenceRing() && (it->second.size() != 1152)){
00238 
00239       if (std::abs(etaPart)>=14 || std::abs(etaPart)<=17 ) {
00240         //std::cout << "etaPart "  << etaPart << " size " << it->second.size() << std::endl;
00241       }
00242       else {
00243         throw cms::Exception("RPCInternal") << "Problem: refring " << it->first 
00244           << " has " << it->second.size() << " strips \n";
00245       }
00246     }
00247     
00248     
00249   }
00250     
00251   // Xcheck, if rings are symettrical 
00252   it = m_ringsMap.begin();
00253   for (;it != m_ringsMap.end(); ++it){
00254     int key = it->first;
00255     int sign = key/100 - (key/1000)*10;
00256     
00257     if (sign == 0) {
00258       key += 100;
00259     } else {
00260       key -= 100;
00261     }
00262     
00263     if  (key != 2000){// Hey 2100 has no counterring
00264       if (it->second.size() !=  m_ringsMap[key].size())  
00265       {
00266          throw cms::Exception("RPCInternal") << " Size differs for ring " << key << " +- 100 \n";
00267       }
00268     }
00269   
00270   
00271   }
00272       
00273   buildConnections();
00274 }
00275 
00276 
00277 void RPCConeBuilder::buildConnections(){
00278 
00279 
00280 
00281    RPCStripsRing::TIdToRindMap::iterator itRef = m_ringsMap.begin();
00282    for (;itRef != m_ringsMap.end(); ++itRef){ // iterate over reference rings
00283       
00284       
00285       RPCStripsRing::TOtherConnStructVec ringsToConnect; 
00286       
00287       if (!itRef->second.isReferenceRing()) continue; // iterate over reference rings
00288       
00289       RPCStripsRing::TIdToRindMap::iterator itOther = m_ringsMap.begin();
00290       for (;itOther != m_ringsMap.end(); ++itOther){ // iterate over nonreference rings
00291          
00292          if (itOther->second.isReferenceRing()) continue; // iterate over nonreference rings
00293          
00294          std::pair<int,int> pr = areConnected(itRef, itOther);
00295          if ( pr.first != -1 ) {
00296             RPCStripsRing::TOtherConnStruct newOtherConn;
00297             newOtherConn.m_it = itOther;
00298             newOtherConn.m_logplane = pr.first;
00299             newOtherConn.m_logplaneSize = pr.second;
00300             ringsToConnect.push_back(newOtherConn);
00301          }
00302          
00303          
00304       } // OtherRings iteration ends
00305       
00306       // 
00307       std::pair<int,int> prRef = areConnected(itRef, itRef);
00308       if (prRef.first == -1){
00309         throw cms::Exception("RPCConfig") << " Cannot determine logplane for reference ring "
00310             << itRef->first << "\n ";
00311       }
00312 
00313       /*&
00314       if (prRef.second != 8){
00315         // XXX        
00316         throw cms::Exception("RPCConfig") << " logplaneSize for reference ring "
00317             << itRef->first << " wrong "
00318             << " logplane: " << prRef.first
00319             << " etaPart: " << itRef->second.getEtaPartition()
00320             << " tower: " << itRef->second.getTowerForRefRing()
00321             << " hwPlane: " << itRef->second.getHwPlane()
00322             << " strips " << prRef.second << "\n";
00323       }*/
00324       
00325       itRef->second.createRefConnections(ringsToConnect, prRef.first, prRef.second);
00326       
00327    } // RefRings iteration ends
00328 
00329    
00330    // Fetch connection data, and save in one place
00331    /*
00332    RPCStripsRing::TIdToRindMap::iterator it = m_ringsMap.begin();
00333    for (;it != m_ringsMap.end(); ++it) { 
00334      
00335      L1RPCConeBuilder::TConMap nmap = it->second.getConnectionsMap();
00336      L1RPCConeBuilder::TConMap::iterator newMapIt = nmap.begin();
00337      for (; newMapIt != nmap.end(); ++ newMapIt) {
00338        uint32_t raw = newMapIt->first;
00339        TStrip2ConVec stripsVec = newMapIt->second;
00340        TStrip2ConVec::iterator stripIt = stripsVec.first
00341        //unsigned char strip = 
00342      
00343      
00344      }
00345      
00346      
00347   }*/
00348    
00349 }
00350 
00351 // first - logplane
00352 // second - logplanesize
00353 std::pair<int, int> RPCConeBuilder::areConnected(RPCStripsRing::TIdToRindMap::iterator ref,
00354                                   RPCStripsRing::TIdToRindMap::iterator other){
00355 
00356   int logplane = -1;
00357   
00358   //std::cout << "Checking " << ref->first << " and " << other->first << std::endl;
00359   
00360   // Do not connect  rolls lying on the oposite side of detector
00361   if ( ref->second.getEtaPartition()*other->second.getEtaPartition()<0  )
00362     return std::make_pair(-1,0);  
00363   
00364   
00365   /*std::cout << "Ref " << ref->second.getEtaPartition() << " " <<ref->second.getHwPlane() << std::endl;
00366   std::cout << "Other " << other->second.getEtaPartition() << " " <<other->second.getHwPlane() << std::endl;
00367   std::cout.flush();*/
00368   
00369   // refRing and otherRing areConnected, if they contribute to the same tower
00370   /*
00371   L1RPCConeDefinition::TTowerList refTowList 
00372       = m_L1RPCConeDefinition->getRingsToTowers().at(std::abs(ref->second.getEtaPartition()))
00373                          .at(ref->second.getHwPlane()-1);
00374       
00375 
00376   L1RPCConeDefinition::TTowerList otherTowList 
00377       = m_L1RPCConeDefinition->getRingsToTowers().at(std::abs(other->second.getEtaPartition()))
00378                          .at(other->second.getHwPlane()-1);
00379   */
00380 
00381   L1RPCConeDefinition::TRingToTowerVec::const_iterator itRef
00382       = m_L1RPCConeDefinition->getRingToTowerVec().begin();
00383   
00384   const L1RPCConeDefinition::TRingToTowerVec::const_iterator itEnd 
00385       = m_L1RPCConeDefinition->getRingToTowerVec().end();
00386     
00387   L1RPCConeDefinition::TRingToTowerVec::const_iterator itOther = itRef;
00388   
00389   int refTowerCnt = 0;
00390   int index = -1;
00391   int refTower = -1;
00392   
00393   for (;itRef != itEnd; ++itRef){
00394     if ( itRef->m_etaPart != std::abs(ref->second.getEtaPartition())
00395         || itRef->m_hwPlane != std::abs(ref->second.getHwPlane()-1) // -1?
00396        ) continue;
00397       
00398     ++refTowerCnt;
00399     refTower = itRef->m_tower;
00400     
00401     for (;itOther != itEnd; ++itOther){
00402       if ( itOther->m_etaPart != std::abs(other->second.getEtaPartition())
00403         || itOther->m_hwPlane != std::abs(other->second.getHwPlane()-1) // -1?
00404         ) continue;  
00405       
00406       if (itOther->m_tower == refTower) index = itOther->m_index;
00407       
00408     }
00409     
00410   }
00411   
00412   if(refTowerCnt>1){
00413     throw cms::Exception("RPCConeBuilder") << " Reference(?) ring "
00414         << ref->first << " "
00415         << "wants to be connected to " << refTowerCnt << " towers \n";
00416   
00417   }
00418 
00419   if(refTowerCnt==0){
00420     throw cms::Exception("RPCConeBuilder") << " Reference(?) ring "
00421         << ref->first << " "
00422         << " is not connected anywhere \n";
00423   
00424   }
00425   
00426   /*  
00427   if(index == -1){
00428     throw cms::Exception("RPCConeBuilder") << "Wrong Index -1 \n"
00429                                   }*/
00430   
00431   
00432   /*
00433   int refTower = -1;
00434   
00435   L1RPCConeDefinition::TTowerList::iterator rtlIt = refTowList.begin();
00436   for (; rtlIt != refTowList.end(); ++rtlIt){
00437   
00438      if ( *rtlIt >= 0 && refTower < 0){
00439         refTower = *rtlIt;
00440      }
00441      else if ( *rtlIt >= 0 && refTower >= 0) {
00442       throw cms::Exception("RPCConfig") << " Reference(?) ring "
00443             << ref->first << " "
00444             << "wants to be connected more than one tower: "
00445             << refTower << " "
00446             << *rtlIt << "\n";
00447      
00448      }
00449   
00450   }
00451   
00452   if (refTower < 0) {
00453      throw cms::Exception("RPCConfig") << " Reference(?) ring "
00454            << ref->first
00455            << " is not connected anywhere \n";
00456   }
00457   
00458   L1RPCConeDefinition::TTowerList::iterator otlIt = otherTowList.begin();
00459   
00460   int index = -1, i = 0;
00461   for (; otlIt != otherTowList.end(); ++otlIt){
00462      if (*otlIt == refTower) {
00463         index = i;
00464      }
00465      ++i;
00466   }
00467   */
00468   
00469   int lpSize = 0;
00470   if (index != -1){
00471     /*
00472     logplane = m_L1RPCConeDefinition->getRingsToLP().at(std::abs(other->second.getEtaPartition()))
00473            .at(other->second.getHwPlane()-1)
00474     .at(index);*/
00475     {
00476       L1RPCConeDefinition::TRingToLPVec::const_iterator it = m_L1RPCConeDefinition->getRingToLPVec().begin();
00477       L1RPCConeDefinition::TRingToLPVec::const_iterator itEnd = m_L1RPCConeDefinition->getRingToLPVec().end();
00478       for (;it!=itEnd;++it){
00479         
00480         if (it->m_etaPart != std::abs(other->second.getEtaPartition())
00481             || it->m_hwPlane != std::abs(other->second.getHwPlane()-1) 
00482             || it->m_index != index) continue;
00483         
00484         logplane = it->m_LP;  
00485         
00486       }
00487     }    
00488     //lpSize = m_L1RPCConeDefinition->getLPSizeForTowers().at(refTower).at(logplane-1);
00489     
00490     {
00491       L1RPCConeDefinition::TLPSizeVec::const_iterator it = m_L1RPCConeDefinition->getLPSizeVec().begin();
00492       L1RPCConeDefinition::TLPSizeVec::const_iterator itEnd = m_L1RPCConeDefinition->getLPSizeVec().end();
00493       for (;it!=itEnd;++it){
00494               
00495         //std::cout << it->m_LP  << " " << logplane << std::endl;
00496         if (it->m_tower != std::abs(refTower) || it->m_LP != logplane-1) continue;
00497         lpSize = it->m_size;
00498               
00499       }
00500   
00501               //FIXME
00502       if (lpSize==-1) {
00503                 //throw cms::Exception("getLogStrip") << " lpSize==-1\n";
00504       }
00505     }
00506   }
00507   
00508   
00509   /*
00510   if (logplane != -1){
00511     
00512      std::cout << ref->first << " <-> " << other->first 
00513            << " logplane " << logplane
00514            << " lpsize " << lpSize 
00515            << std::endl;
00516   }//*/
00517   
00518   return std::make_pair(logplane,lpSize);
00519 
00520 }
00521 
00522 
00523