CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/L1Trigger/RPCTechnicalTrigger/src/RBCProcessRPCSimDigis.cc

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