CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/L1Trigger/RPCTechnicalTrigger/src/RBCProcessRPCDigis.cc

Go to the documentation of this file.
00001 // $Id: RBCProcessRPCDigis.cc,v 1.6 2013/03/20 15:45:25 wdd Exp $
00002 // Include files 
00003 
00004 
00005 
00006 // local
00007 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCProcessRPCDigis.h"
00008 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCLinkBoardGLSignal.h"
00009 #include "DataFormats/Common/interface/Handle.h"
00010 
00011 //-----------------------------------------------------------------------------
00012 // Implementation file for class : RBCProcessRPCDigis
00013 //
00014 // 2009-04-15 : Andres Felipe Osorio Oliveros
00015 //-----------------------------------------------------------------------------
00016 
00017 //=============================================================================
00018 // Standard constructor, initializes variables
00019 //=============================================================================
00020 RBCProcessRPCDigis::RBCProcessRPCDigis(  const edm::ESHandle<RPCGeometry> & rpcGeom, 
00021                                          const edm::Handle<RPCDigiCollection> & digiColl ) 
00022 {
00023   
00024   m_ptr_rpcGeom  = & rpcGeom;
00025   m_ptr_digiColl = & digiColl;
00026   
00027   m_lbin = dynamic_cast<RPCInputSignal*>( new RBCLinkBoardGLSignal( &m_data ) );
00028   
00029   m_debug = false;
00030   
00031   configure();
00032   
00033 }
00034 
00035 void RBCProcessRPCDigis::configure() 
00036 {
00037   
00038   m_wheelid.push_back(-2); //-2
00039   m_wheelid.push_back(-1); //-1
00040   m_wheelid.push_back(0);  // 0
00041   m_wheelid.push_back( 1); //+1
00042   m_wheelid.push_back( 2); //+2
00043   
00044   m_sec1id.push_back(12);
00045   m_sec2id.push_back(1);
00046   m_sec1id.push_back(2);
00047   m_sec2id.push_back(3);
00048   m_sec1id.push_back(4);
00049   m_sec2id.push_back(5);
00050   m_sec1id.push_back(6);
00051   m_sec2id.push_back(7);
00052   m_sec1id.push_back(8);
00053   m_sec2id.push_back(9);
00054   m_sec1id.push_back(10);
00055   m_sec2id.push_back(11);
00056   
00057   m_layermap[113]     = 0;  //RB1InFw
00058   m_layermap[123]     = 1;  //RB1OutFw
00059   
00060   m_layermap[20213]   = 2;  //RB22Fw
00061   m_layermap[20223]   = 2;  //RB22Fw
00062   m_layermap[30223]   = 3;  //RB23Fw
00063   m_layermap[30213]   = 3;  //RB23Fw
00064   m_layermap[30212]   = 4;  //RB23M
00065   m_layermap[30222]   = 4;  //RB23M
00066   
00067   m_layermap[313]     = 5;  //RB3Fw
00068   m_layermap[413]     = 6;  //RB4Fw
00069   m_layermap[111]     = 7;  //RB1InBk
00070   m_layermap[121]     = 8;  //RB1OutBk
00071   
00072   m_layermap[20211]   = 9;  //RB22Bw
00073   m_layermap[20221]   = 9;  //RB22Bw
00074   m_layermap[30211]   = 10; //RB23Bw
00075   m_layermap[30221]   = 10; //RB23Bw
00076   
00077   m_layermap[311]     = 11; //RB3Bk
00078   m_layermap[411]     = 12; //RB4Bk
00079 
00080   m_maxBxWindow = 3;
00081 
00082   std::vector<int>::iterator wheel;
00083 
00084   for( wheel = m_wheelid.begin(); wheel != m_wheelid.end(); ++wheel)
00085     m_digiCounters[(*wheel)] = new l1trigger::Counters( (*wheel) );
00086   
00087 }
00088 
00089 //=============================================================================
00090 // Destructor
00091 //=============================================================================
00092 RBCProcessRPCDigis::~RBCProcessRPCDigis() {
00093   
00094   if ( m_lbin ) delete m_lbin;
00095 
00096   std::vector<int>::iterator wheel;
00097   
00098   for( wheel = m_wheelid.begin(); wheel != m_wheelid.end(); ++wheel)
00099     delete m_digiCounters[(*wheel)];
00100   
00101   m_sec1id.clear();
00102   m_sec2id.clear();
00103   m_wheelid.clear();
00104   m_layermap.clear();
00105   
00106   reset();
00107     
00108 } 
00109 
00110 //=============================================================================
00111 int RBCProcessRPCDigis::next() {
00112   
00113   //...clean up previous data contents
00114   
00115   reset();
00116   
00117   int ndigis(0);
00118   
00119   for (m_detUnitItr = (*m_ptr_digiColl)->begin(); 
00120        m_detUnitItr != (*m_ptr_digiColl)->end(); ++m_detUnitItr ) {
00121     
00122     if ( m_debug ) std::cout << "looping over digis 1 ..." << std::endl;
00123     
00124     m_digiItr = (*m_detUnitItr ).second.first;
00125     int bx = (*m_digiItr).bx();
00126     
00127     if ( abs(bx) >= m_maxBxWindow ) {
00128       if ( m_debug )  std::cout << "RBCProcessRPCDigis> found a bx bigger than max allowed: "
00129                                 << bx << std::endl;
00130       continue;
00131     }
00132     
00133     const RPCDetId & id  = (*m_detUnitItr).first;
00134     const RPCRoll * roll = dynamic_cast<const RPCRoll* >( (*m_ptr_rpcGeom)->roll(id));
00135     
00136     if((roll->isForward())) {
00137       if( m_debug ) std::cout << "RBCProcessRPCDigis: roll is forward" << std::endl;
00138       continue;
00139     }
00140     
00141     int wheel   = roll->id().ring();                    // -2,-1,0,+1,+2
00142     int sector  = roll->id().sector();                  // 1 to 12 
00143     int layer   = roll->id().layer();                   // 1,2
00144     int station = roll->id().station();                 // 1-4
00145     int blayer  = getBarrelLayer( layer, station );     // 1 to 6
00146     int rollid  = id.roll();
00147     
00148     int digipos = (station * 100) + (layer * 10) + rollid;
00149     
00150     if ( (wheel == -1 || wheel == 0 || wheel == 1) && station == 2 && layer == 1 )
00151       digipos = 30000 + digipos;
00152     if ( (wheel == -2 || wheel == 2) && station == 2 && layer == 2 )
00153       digipos = 30000 + digipos;
00154     
00155     if ( (wheel == -1 || wheel == 0 || wheel == 1) && station == 2 && layer == 2 )
00156       digipos = 20000 + digipos;
00157     if ( (wheel == -2 || wheel == 2) && station == 2 && layer == 1 )
00158       digipos = 20000 + digipos;
00159     
00160     if ( m_debug ) std::cout << "Bx: "      << bx      << '\t'
00161                              << "Wheel: "   << wheel   << '\t'
00162                              << "Sector: "  << sector  << '\t'
00163                              << "Station: " << station << '\t'
00164                              << "Layer: "   << layer   << '\t'
00165                              << "B-Layer: " << blayer  << '\t'
00166                              << "Roll id: " << rollid  << '\t'
00167                              << "Digi at: " << digipos << '\n';
00168     
00169     //... Construct the RBCinput objects
00170     std::map<int,std::vector<RPCData*> >::iterator itr;
00171     itr = m_vecDataperBx.find( bx );
00172     
00173     if ( itr == m_vecDataperBx.end() ) {
00174       if ( m_debug ) std::cout << "Found a new Bx: " << bx << std::endl;
00175       std::vector<RPCData*> wheelData;
00176       initialize(wheelData);
00177       m_vecDataperBx[bx] = wheelData; 
00178       this->m_block = wheelData[ (wheel + 2) ];
00179       setDigiAt( sector, digipos );
00180     }
00181     else{
00182       this->m_block = (*itr).second[ (wheel + 2) ];
00183       setDigiAt( sector, digipos );
00184     }
00185     
00186     std::map<int, l1trigger::Counters* >::iterator wheelCounter;
00187     wheelCounter = m_digiCounters.find( wheel );
00188     
00189     if ( wheelCounter != m_digiCounters.end() )
00190       (*wheelCounter).second->incrementSector( sector );
00191     
00192     if ( m_debug ) std::cout << "looping over digis 2 ..." << std::endl;
00193     
00194     ++ndigis;
00195     
00196   }
00197   
00198   if ( m_debug ) std::cout << "size of data vectors: " << m_vecDataperBx.size() << std::endl;
00199   
00200   builddata();
00201   
00202   if ( m_debug ) {
00203     std::cout << "after reset" << std::endl;
00204     print_output();
00205   }
00206   
00207   if ( m_debug ) std::cout << "RBCProcessRPCDigis: DataSize: " << m_data.size() 
00208                            << " ndigis " << ndigis << std::endl;
00209   
00210   std::map<int, l1trigger::Counters* >::iterator wheelCounter;
00211   for( wheelCounter = m_digiCounters.begin(); wheelCounter != m_digiCounters.end(); ++wheelCounter) {
00212     (*wheelCounter).second->evalCounters();
00213     if ( m_debug ) (*wheelCounter).second->printSummary();
00214   }
00215   
00216   if ( m_data.size() <= 0 ) return 0;
00217   
00218   return 1;
00219   
00220 }
00221 
00222 void RBCProcessRPCDigis::reset()
00223 {
00224   
00225   std::map<int,std::vector<RPCData*> >::iterator itr1;
00226   for( itr1 = m_vecDataperBx.begin(); itr1 != m_vecDataperBx.end(); ++itr1) {
00227     std::vector<RPCData*>::iterator itr2;
00228     for(itr2 = (*itr1).second.begin(); itr2 != (*itr1).second.end();++itr2 )
00229       if ( (*itr2) ) delete *itr2;
00230     (*itr1).second.clear();
00231   }
00232   m_vecDataperBx.clear();
00233   
00234 }
00235 
00236 
00237 void RBCProcessRPCDigis::initialize( std::vector<RPCData*> & dataVec ) 
00238 {
00239   
00240   if ( m_debug ) std::cout << "initialize" << std::endl;
00241   
00242   int maxWheels = 5;
00243   int maxRbcBrds = 6;
00244   
00245   for(int i=0; i < maxWheels; ++i) {
00246     
00247     m_block = new RPCData();
00248     
00249     m_block->m_wheel = m_wheelid[i];
00250     
00251     for(int j=0; j < maxRbcBrds; ++j) {
00252       m_block->m_sec1[j] = m_sec1id[j];
00253       m_block->m_sec2[j] = m_sec2id[j];
00254       m_block->m_orsignals[j].input_sec[0].reset();
00255       m_block->m_orsignals[j].input_sec[1].reset();
00256       m_block->m_orsignals[j].needmapping = false;
00257       m_block->m_orsignals[j].hasData = false;
00258     }
00259 
00260     dataVec.push_back( m_block );
00261     
00262   }
00263   
00264   if ( m_debug ) std::cout << "initialize: completed" << std::endl;
00265   
00266 }
00267 
00268 void RBCProcessRPCDigis::builddata() 
00269 {
00270   
00271   int bx(0);
00272   int code(0);
00273   int bxsign(1);
00274   std::vector<RPCData*>::iterator itr;
00275   std::map<int, std::vector<RPCData*> >::iterator itr2;
00276   
00277   itr2 = m_vecDataperBx.begin();
00278   if( itr2 == ( m_vecDataperBx.end() ) ) return;
00279   
00280   while ( itr2 != m_vecDataperBx.end() ) {
00281     
00282     bx = (*itr2).first;
00283     
00284     if ( bx != 0 ) bxsign = ( bx / abs(bx) );
00285     else bxsign = 1;
00286     
00287     for(itr = (*itr2).second.begin(); itr != (*itr2).second.end(); ++itr) {
00288       
00289       for(int k=0; k < 6; ++k) {
00290         
00291         code = bxsign * ( 1000000*abs(bx)
00292                           + 10000*(*itr)->wheelIdx()
00293                           + 100  *(*itr)->m_sec1[k]
00294                           + 1    *(*itr)->m_sec2[k] );
00295         
00296         RBCInput * signal = & (*itr)->m_orsignals[k];
00297         signal->needmapping = false;
00298         
00299         if ( signal->hasData )
00300           m_data.insert( std::make_pair( code , signal) );
00301         
00302       }
00303     }
00304     
00305     ++itr2;
00306     
00307   }
00308   
00309   if ( m_debug ) std::cout << "builddata: completed. size of data: " << m_data.size() << std::endl;
00310   
00311 }
00312 
00313 int RBCProcessRPCDigis::getBarrelLayer( const int & _layer, const int & _station )
00314 {
00315   
00316   //... Calculates the generic Barrel Layer (1 to 6)
00317   int blayer(0);
00318   
00319   if ( _station < 3 ) {
00320     blayer = ( (_station-1) * 2 ) + _layer;
00321   }
00322   else {
00323     blayer = _station + 2;
00324   }
00325   
00326   return blayer;
00327   
00328 }
00329 
00330 
00331 void RBCProcessRPCDigis::setDigiAt( int sector, int digipos )
00332 {
00333   
00334   int pos   = 0;
00335   int isAoB = 0;
00336 
00337   if ( m_debug ) std::cout << "setDigiAt" << std::endl;
00338   
00339   std::vector<int>::const_iterator itr;
00340   itr = std::find( m_sec1id.begin(), m_sec1id.end(), sector );
00341   
00342   if ( itr == m_sec1id.end()) {
00343     itr = std::find( m_sec2id.begin(), m_sec2id.end(), sector );
00344     isAoB = 1;
00345   } 
00346   
00347   for ( pos = 0; pos < 6; ++pos ) {
00348     if (this->m_block->m_sec1[pos] == sector || this->m_block->m_sec2[pos] == sector )
00349       break;
00350   }
00351   
00352   if ( m_debug ) std::cout << this->m_block->m_orsignals[pos];
00353   
00354   setInputBit( this->m_block->m_orsignals[pos].input_sec[ isAoB ] , digipos );
00355   
00356   this->m_block->m_orsignals[pos].hasData = true;
00357   
00358   if ( m_debug ) std::cout << this->m_block->m_orsignals[pos];
00359   
00360   if ( m_debug ) std::cout << "setDigiAt completed" << std::endl;
00361   
00362 }
00363 
00364 void RBCProcessRPCDigis::setInputBit( std::bitset<15> & signals , int digipos ) 
00365 {
00366   
00367   int bitpos = m_layermap[digipos];
00368   if( m_debug ) std::cout << "Bitpos: " << bitpos << std::endl;
00369   signals.set( bitpos , 1 );
00370   
00371 }
00372 
00373 void  RBCProcessRPCDigis::print_output() 
00374 {
00375 
00376   std::cout << "RBCProcessRPCDigis> Output starts" << std::endl;
00377   
00378   std::map<int,RBCInput*>::const_iterator itr;
00379   for( itr = m_data.begin(); itr != m_data.end(); ++itr) {
00380     std::cout << (*itr).first << '\t' << (* (*itr).second ) << '\n';
00381   }
00382 
00383   std::cout << "RBCProcessRPCDigis> Output ends" << std::endl;
00384   
00385 }
00386