CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/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.2 2009/09/15 13:49:41 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     if (it->second.isReferenceRing() && (it->second.size() != 1152)){
00236       throw cms::Exception("RPCInternal") << "Problem: refring " << it->first 
00237           << " has " << it->second.size() << " strips \n";
00238     }
00239     
00240     
00241   }
00242     
00243   // Xcheck, if rings are symettrical 
00244   it = m_ringsMap.begin();
00245   for (;it != m_ringsMap.end(); ++it){
00246     int key = it->first;
00247     int sign = key/100 - (key/1000)*10;
00248     
00249     if (sign == 0) {
00250       key += 100;
00251     } else {
00252       key -= 100;
00253     }
00254     
00255     if  (key != 2000){// Hey 2100 has no counterring
00256       if (it->second.size() !=  m_ringsMap[key].size())  
00257       {
00258          throw cms::Exception("RPCInternal") << " Size differs for ring " << key << " +- 100 \n";
00259       }
00260     }
00261   
00262   
00263   }
00264       
00265   buildConnections();
00266 }
00267 
00268 
00269 void RPCConeBuilder::buildConnections(){
00270 
00271 
00272 
00273    RPCStripsRing::TIdToRindMap::iterator itRef = m_ringsMap.begin();
00274    for (;itRef != m_ringsMap.end(); ++itRef){ // iterate over reference rings
00275       
00276       
00277       RPCStripsRing::TOtherConnStructVec ringsToConnect; 
00278       
00279       if (!itRef->second.isReferenceRing()) continue; // iterate over reference rings
00280       
00281       RPCStripsRing::TIdToRindMap::iterator itOther = m_ringsMap.begin();
00282       for (;itOther != m_ringsMap.end(); ++itOther){ // iterate over nonreference rings
00283          
00284          if (itOther->second.isReferenceRing()) continue; // iterate over nonreference rings
00285          
00286          std::pair<int,int> pr = areConnected(itRef, itOther);
00287          if ( pr.first != -1 ) {
00288             RPCStripsRing::TOtherConnStruct newOtherConn;
00289             newOtherConn.m_it = itOther;
00290             newOtherConn.m_logplane = pr.first;
00291             newOtherConn.m_logplaneSize = pr.second;
00292             ringsToConnect.push_back(newOtherConn);
00293          }
00294          
00295          
00296       } // OtherRings iteration ends
00297       
00298       // 
00299       std::pair<int,int> prRef = areConnected(itRef, itRef);
00300       if (prRef.first == -1){
00301         throw cms::Exception("RPCConfig") << " Cannot determine logplane for reference ring "
00302             << itRef->first << "\n ";
00303       }
00304       if (prRef.second != 8){
00305         // XXX        
00306         throw cms::Exception("RPCConfig") << " logplaneSize for reference ring "
00307             << itRef->first << " wrong "
00308             << " logplane: " << prRef.first
00309             << " etaPart: " << itRef->second.getEtaPartition()
00310             << " tower: " << itRef->second.getTowerForRefRing()
00311             << " hwPlane: " << itRef->second.getHwPlane()
00312             << " strips " << prRef.second << "\n";
00313       }
00314       
00315       itRef->second.createRefConnections(ringsToConnect, prRef.first, prRef.second);
00316       
00317    } // RefRings iteration ends
00318 
00319    
00320    // Fetch connection data, and save in one place
00321    /*
00322    RPCStripsRing::TIdToRindMap::iterator it = m_ringsMap.begin();
00323    for (;it != m_ringsMap.end(); ++it) { 
00324      
00325      L1RPCConeBuilder::TConMap nmap = it->second.getConnectionsMap();
00326      L1RPCConeBuilder::TConMap::iterator newMapIt = nmap.begin();
00327      for (; newMapIt != nmap.end(); ++ newMapIt) {
00328        uint32_t raw = newMapIt->first;
00329        TStrip2ConVec stripsVec = newMapIt->second;
00330        TStrip2ConVec::iterator stripIt = stripsVec.first
00331        //unsigned char strip = 
00332      
00333      
00334      }
00335      
00336      
00337   }*/
00338    
00339 }
00340 
00341 // first - logplane
00342 // second - logplanesize
00343 std::pair<int, int> RPCConeBuilder::areConnected(RPCStripsRing::TIdToRindMap::iterator ref,
00344                                   RPCStripsRing::TIdToRindMap::iterator other){
00345 
00346   int logplane = -1;
00347   
00348   //std::cout << "Checking " << ref->first << " and " << other->first << std::endl;
00349   
00350   // Do not connect  rolls lying on the oposite side of detector
00351   if ( ref->second.getEtaPartition()*other->second.getEtaPartition()<0  )
00352     return std::make_pair(-1,0);  
00353   
00354   
00355   /*std::cout << "Ref " << ref->second.getEtaPartition() << " " <<ref->second.getHwPlane() << std::endl;
00356   std::cout << "Other " << other->second.getEtaPartition() << " " <<other->second.getHwPlane() << std::endl;
00357   std::cout.flush();*/
00358   
00359   // refRing and otherRing areConnected, if they contribute to the same tower
00360   /*
00361   L1RPCConeDefinition::TTowerList refTowList 
00362       = m_L1RPCConeDefinition->getRingsToTowers().at(std::abs(ref->second.getEtaPartition()))
00363                          .at(ref->second.getHwPlane()-1);
00364       
00365 
00366   L1RPCConeDefinition::TTowerList otherTowList 
00367       = m_L1RPCConeDefinition->getRingsToTowers().at(std::abs(other->second.getEtaPartition()))
00368                          .at(other->second.getHwPlane()-1);
00369   */
00370 
00371   L1RPCConeDefinition::TRingToTowerVec::const_iterator itRef
00372       = m_L1RPCConeDefinition->getRingToTowerVec().begin();
00373   
00374   const L1RPCConeDefinition::TRingToTowerVec::const_iterator itEnd 
00375       = m_L1RPCConeDefinition->getRingToTowerVec().end();
00376     
00377   L1RPCConeDefinition::TRingToTowerVec::const_iterator itOther = itRef;
00378   
00379   int refTowerCnt = 0;
00380   int index = -1;
00381   int refTower = -1;
00382   
00383   for (;itRef != itEnd; ++itRef){
00384     if ( itRef->m_etaPart != std::abs(ref->second.getEtaPartition())
00385         || itRef->m_hwPlane != std::abs(ref->second.getHwPlane()-1) // -1?
00386        ) continue;
00387       
00388     ++refTowerCnt;
00389     refTower = itRef->m_tower;
00390     
00391     for (;itOther != itEnd; ++itOther){
00392       if ( itOther->m_etaPart != std::abs(other->second.getEtaPartition())
00393         || itOther->m_hwPlane != std::abs(other->second.getHwPlane()-1) // -1?
00394         ) continue;  
00395       
00396       if (itOther->m_tower == refTower) index = itOther->m_index;
00397       
00398     }
00399     
00400   }
00401   
00402   if(refTowerCnt>1){
00403     throw cms::Exception("RPCConeBuilder") << " Reference(?) ring "
00404         << ref->first << " "
00405         << "wants to be connected to " << refTowerCnt << " towers \n";
00406   
00407   }
00408 
00409   if(refTowerCnt==0){
00410     throw cms::Exception("RPCConeBuilder") << " Reference(?) ring "
00411         << ref->first << " "
00412         << " is not connected anywhere \n";
00413   
00414   }
00415   
00416   /*  
00417   if(index == -1){
00418     throw cms::Exception("RPCConeBuilder") << "Wrong Index -1 \n"
00419                                   }*/
00420   
00421   
00422   /*
00423   int refTower = -1;
00424   
00425   L1RPCConeDefinition::TTowerList::iterator rtlIt = refTowList.begin();
00426   for (; rtlIt != refTowList.end(); ++rtlIt){
00427   
00428      if ( *rtlIt >= 0 && refTower < 0){
00429         refTower = *rtlIt;
00430      }
00431      else if ( *rtlIt >= 0 && refTower >= 0) {
00432       throw cms::Exception("RPCConfig") << " Reference(?) ring "
00433             << ref->first << " "
00434             << "wants to be connected more than one tower: "
00435             << refTower << " "
00436             << *rtlIt << "\n";
00437      
00438      }
00439   
00440   }
00441   
00442   if (refTower < 0) {
00443      throw cms::Exception("RPCConfig") << " Reference(?) ring "
00444            << ref->first
00445            << " is not connected anywhere \n";
00446   }
00447   
00448   L1RPCConeDefinition::TTowerList::iterator otlIt = otherTowList.begin();
00449   
00450   int index = -1, i = 0;
00451   for (; otlIt != otherTowList.end(); ++otlIt){
00452      if (*otlIt == refTower) {
00453         index = i;
00454      }
00455      ++i;
00456   }
00457   */
00458   
00459   int lpSize = 0;
00460   if (index != -1){
00461     /*
00462     logplane = m_L1RPCConeDefinition->getRingsToLP().at(std::abs(other->second.getEtaPartition()))
00463            .at(other->second.getHwPlane()-1)
00464     .at(index);*/
00465     {
00466       L1RPCConeDefinition::TRingToLPVec::const_iterator it = m_L1RPCConeDefinition->getRingToLPVec().begin();
00467       L1RPCConeDefinition::TRingToLPVec::const_iterator itEnd = m_L1RPCConeDefinition->getRingToLPVec().end();
00468       for (;it!=itEnd;++it){
00469         
00470         if (it->m_etaPart != std::abs(other->second.getEtaPartition())
00471             || it->m_hwPlane != std::abs(other->second.getHwPlane()-1) 
00472             || it->m_index != index) continue;
00473         
00474         logplane = it->m_LP;  
00475         
00476       }
00477     }    
00478     //lpSize = m_L1RPCConeDefinition->getLPSizeForTowers().at(refTower).at(logplane-1);
00479     
00480     {
00481       L1RPCConeDefinition::TLPSizeVec::const_iterator it = m_L1RPCConeDefinition->getLPSizeVec().begin();
00482       L1RPCConeDefinition::TLPSizeVec::const_iterator itEnd = m_L1RPCConeDefinition->getLPSizeVec().end();
00483       for (;it!=itEnd;++it){
00484               
00485         //std::cout << it->m_LP  << " " << logplane << std::endl;
00486         if (it->m_tower != std::abs(refTower) || it->m_LP != logplane-1) continue;
00487         lpSize = it->m_size;
00488               
00489       }
00490   
00491               //FIXME
00492       if (lpSize==-1) {
00493                 //throw cms::Exception("getLogStrip") << " lpSize==-1\n";
00494       }
00495     }
00496   }
00497   
00498   
00499   /*
00500   if (logplane != -1){
00501     
00502      std::cout << ref->first << " <-> " << other->first 
00503            << " logplane " << logplane
00504            << " lpsize " << lpSize 
00505            << std::endl;
00506   }//*/
00507   
00508   return std::make_pair(logplane,lpSize);
00509 
00510 }
00511 
00512 
00513