CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/EventFilter/EcalRawToDigi/src/EcalElectronicsMapper.cc

Go to the documentation of this file.
00001 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00002 #include <EventFilter/EcalRawToDigi/interface/EcalElectronicsMapper.h>
00003 #include <Geometry/EcalMapping/interface/EcalElectronicsMapping.h>
00004 #include <DataFormats/EcalDigi/interface/EBSrFlag.h>
00005 #include <DataFormats/EcalDigi/interface/EESrFlag.h>
00006 #include <EventFilter/EcalRawToDigi/interface/DCCDataUnpacker.h>
00007 
00008 EcalElectronicsMapper::EcalElectronicsMapper( unsigned int numbXtalTSamples, unsigned int numbTriggerTSamples)
00009 : pathToMapFile_(""),
00010 numbXtalTSamples_(numbXtalTSamples),
00011 numbTriggerTSamples_(numbTriggerTSamples),
00012 mappingBuilder_(0)
00013 {
00014   resetPointers();
00015   setupGhostMap();
00016 }
00017 
00018 void EcalElectronicsMapper::resetPointers(){
00019   
00020   // Reset Arrays
00021   for(unsigned int sm=0; sm < NUMB_SM; sm++){
00022     for(unsigned int fe=0; fe< NUMB_FE; fe++){
00023           
00024       for(unsigned int strip=0; strip<NUMB_STRIP;strip++){
00025         for(unsigned int xtal=0; xtal<NUMB_XTAL;xtal++){
00026                     
00027              //Reset DFrames and xtalDetIds
00028           xtalDetIds_[sm][fe][strip][xtal]=0;
00029         }
00030       }
00031 
00032       //Reset SC Det Ids
00033       //scDetIds_[sm][fe]=0;
00034       scEleIds_[sm][fe]=0;
00035       //srFlags_[sm][fe]=0;
00036     }
00037   }
00038   
00039   
00040   //Reset TT det Ids
00041   for( unsigned int tccid=0; tccid < NUMB_TCC; tccid++){
00042     for(unsigned int tpg =0; tpg<NUMB_FE;tpg++){
00043       ttDetIds_[tccid][tpg]=0;
00044       ttTPIds_[tccid][tpg]=0;
00045       ttEleIds_[tccid][tpg]=0;
00046     }
00047   }
00048 
00049   // reset trigger electronics Id
00050   for (int tccid=0; tccid<NUMB_TCC; tccid++){
00051       for (int ttid=0; ttid<TCC_EB_NUMBTTS; ttid++){
00052           for (int ps=0; ps<NUMB_STRIP; ps++){
00053               psInput_[tccid][ttid][ps]=0;
00054           }}}
00055   
00056   // initialize TCC maps
00057   for (int tccId=0; tccId<EcalTriggerElectronicsId::MAX_TCCID; tccId++) {
00058       for (int psCounter=0; psCounter<EcalTrigTowerDetId::kEBTowersPerSM*5; psCounter++) {
00059           for (int u=0; u<2; u++){
00060               tTandPs_[tccId][psCounter][u]=-1;
00061           } } }
00062   
00063   
00064 
00065   //Fill map sm id to tcc ids
00066   std::vector<unsigned int> * ids;
00067   ids = new std::vector<unsigned int>;
00068   ids->push_back(1); ids->push_back(18);ids->push_back(19);ids->push_back(36);
00069   mapSmIdToTccIds_[1]= ids;
00070                 
00071   ids = new std::vector<unsigned int>;
00072   ids->push_back(2); ids->push_back(3);ids->push_back(20);ids->push_back(21);
00073   mapSmIdToTccIds_[2]= ids;
00074                 
00075   ids = new std::vector<unsigned int>;
00076   ids->push_back(4); ids->push_back(5);ids->push_back(22);ids->push_back(23);
00077   mapSmIdToTccIds_[3]= ids;
00078                 
00079   ids = new std::vector<unsigned int>;
00080   ids->push_back(6); ids->push_back(7);ids->push_back(24);ids->push_back(25);
00081   mapSmIdToTccIds_[4]= ids;
00082                 
00083   ids = new std::vector<unsigned int>;
00084   ids->push_back(8); ids->push_back(9);ids->push_back(26);ids->push_back(27);
00085   mapSmIdToTccIds_[5]= ids;
00086                 
00087   ids = new std::vector<unsigned int>;
00088   ids->push_back(10); ids->push_back(11);ids->push_back(28);ids->push_back(29);
00089   mapSmIdToTccIds_[6]= ids;
00090                 
00091   ids = new std::vector<unsigned int>;
00092   ids->push_back(12); ids->push_back(13);ids->push_back(30);ids->push_back(31);
00093   mapSmIdToTccIds_[7]= ids;
00094                 
00095   ids = new std::vector<unsigned int>;
00096   ids->push_back(14); ids->push_back(15);ids->push_back(32);ids->push_back(33);
00097   mapSmIdToTccIds_[8]= ids;
00098                 
00099   ids = new std::vector<unsigned int>;
00100   ids->push_back(16); ids->push_back(17);ids->push_back(34);ids->push_back(35);
00101   mapSmIdToTccIds_[9]= ids;
00102                 
00103   ids = new std::vector<unsigned int>;
00104   ids->push_back(73); ids->push_back(90);ids->push_back(91);ids->push_back(108);
00105   mapSmIdToTccIds_[46]= ids;
00106                 
00107   ids = new std::vector<unsigned int>;
00108   ids->push_back(74); ids->push_back(75);ids->push_back(92);ids->push_back(93);
00109   mapSmIdToTccIds_[47]= ids;
00110                 
00111   ids = new std::vector<unsigned int>;
00112   ids->push_back(76); ids->push_back(77);ids->push_back(94);ids->push_back(95);
00113   mapSmIdToTccIds_[48]= ids;
00114                 
00115   ids = new std::vector<unsigned int>;
00116   ids->push_back(78); ids->push_back(79);ids->push_back(96);ids->push_back(97);
00117   mapSmIdToTccIds_[49]= ids;
00118                 
00119   ids = new std::vector<unsigned int>;
00120   ids->push_back(80); ids->push_back(81);ids->push_back(98);ids->push_back(99);  
00121   mapSmIdToTccIds_[50]= ids;
00122                  
00123   ids = new std::vector<unsigned int>;
00124   ids->push_back(82); ids->push_back(83);ids->push_back(100);ids->push_back(101);
00125   mapSmIdToTccIds_[51]= ids;
00126                 
00127   ids = new std::vector<unsigned int>;
00128   ids->push_back(84); ids->push_back(85);ids->push_back(102);ids->push_back(103);
00129   mapSmIdToTccIds_[52]= ids;
00130                 
00131   ids = new std::vector<unsigned int>;
00132   ids->push_back(86); ids->push_back(87);ids->push_back(104);ids->push_back(105);
00133   mapSmIdToTccIds_[53]= ids;
00134                 
00135   ids = new std::vector<unsigned int>;
00136   ids->push_back(88); ids->push_back(89);ids->push_back(106);ids->push_back(107);
00137   mapSmIdToTccIds_[54]= ids;
00138         
00139   
00140   //Compute data block sizes
00141   unfilteredFEBlockLength_= computeUnfilteredFEBlockLength();  
00142   ebTccBlockLength_       = computeEBTCCBlockLength();
00143   eeTccBlockLength_       = computeEETCCBlockLength();
00144     
00145 
00146 }
00147 
00148 
00149 EcalElectronicsMapper::~EcalElectronicsMapper(){
00150   deletePointers();
00151 }
00152 
00153 void EcalElectronicsMapper::deletePointers(){
00154 
00155   //DETETE ARRAYS
00156   for(unsigned int sm=0; sm < NUMB_SM; sm++){
00157     for(unsigned int fe=0; fe< NUMB_FE; fe++){
00158       for(unsigned int strip=0; strip<NUMB_STRIP;strip++){
00159         for(unsigned int xtal=0; xtal<NUMB_XTAL;xtal++) delete xtalDetIds_[sm][fe][strip][xtal];         
00160       }
00161 
00162       // if(scDetIds_[sm][fe]){ 
00163       //  delete scDetIds_[sm][fe];
00164       //  delete scEleIds_[sm][fe];
00165       for(size_t i = 0; i< srFlags_[sm][fe].size(); ++i) delete srFlags_[sm][fe][i];
00166       srFlags_[sm][fe].clear();
00167  
00168       delete scEleIds_[sm][fe];
00169            
00170     }
00171  
00172   }
00173 
00174   // delete trigger electronics Id
00175   for (int tccid=0; tccid<NUMB_TCC; tccid++){
00176     for (int ttid=0; ttid<TCC_EB_NUMBTTS; ttid++){
00177       for (int ps=0; ps<NUMB_STRIP; ps++){
00178         delete psInput_[tccid][ttid][ps];
00179       }
00180     }
00181   }
00182 
00183 
00184   
00185   for( unsigned int tccid=0; tccid < NUMB_TCC; tccid++){
00186     for(unsigned int tpg =0; tpg<NUMB_FE;tpg++){
00187       if(ttDetIds_[tccid][tpg]){ 
00188         delete ttDetIds_[tccid][tpg];
00189         delete ttTPIds_[tccid][tpg];
00190         delete ttEleIds_[tccid][tpg];
00191       }
00192     }
00193   }
00194 
00195 
00196   pathToMapFile_.clear();
00197   
00198   
00199   std::map<unsigned int, std::vector<unsigned int> *>::iterator it;
00200   for(it = mapSmIdToTccIds_.begin(); it != mapSmIdToTccIds_.end(); it++ ){ delete (*it).second; }
00201   
00202   mapSmIdToTccIds_.clear();
00203  
00204 }
00205 
00206 void EcalElectronicsMapper::setEcalElectronicsMapping(const EcalElectronicsMapping * m){
00207   mappingBuilder_= m;
00208   fillMaps();
00209 }
00210 
00211 bool EcalElectronicsMapper::setActiveDCC(unsigned int dccId){
00212    
00213   bool ret(true);
00214         
00215   //Update active dcc and associated smId
00216   dccId_ = dccId;
00217    
00218   smId_  = getSMId(dccId_);
00219         
00220   if(!smId_) ret = false;
00221         
00222   return ret;
00223         
00224  } 
00225  
00226  
00227 bool EcalElectronicsMapper::setDCCMapFilePath(std::string aPath_){
00228 
00229   
00230   //try to open a dccMapFile in the given path
00231   std::ifstream dccMapFile_(aPath_.c_str());
00232 
00233   //if not successful return false
00234   if(!dccMapFile_.is_open()) return false;
00235 
00236   //else close file and accept given path
00237   dccMapFile_.close();
00238   pathToMapFile_ = aPath_;
00239 
00240   return true;
00241 }
00242 
00243 
00244 // bool EcalElectronicsMapper::readDCCMapFile(){
00245 
00246 //   //try to open a dccMapFile in the given path
00247 //   std::ifstream dccMapFile_(pathToMapFile_.c_str());
00248   
00249 //   //if not successful return false
00250 //   if(!dccMapFile_.is_open()) return false;
00251   
00252 //   char lineBuf_[100];
00253 //   unsigned int SMId_,DCCId_;
00254 //   // loop while extraction from file is possible
00255 //   dccMapFile_.getline(lineBuf_,10);       //read line from file
00256 //   while (dccMapFile_.good()) {
00257 //     sscanf(lineBuf_,"%u:%u",&SMId_,&DCCId_);
00258 //     myDCCMap_[SMId_] = DCCId_;
00259 //     dccMapFile_.getline(lineBuf_,10);       //read line from file
00260 //   }
00261   
00262   
00263 //   return true;
00264   
00265 // }
00266 
00267 // bool EcalElectronicsMapper::readDCCMapFile(std::string aPath_){
00268 //   //test if path is good
00269 //   edm::FileInPath eff(aPath_);
00270   
00271 //   if(!setDCCMapFilePath(eff.fullPath())) return false;
00272 
00273 //   //read DCC map file
00274 //   readDCCMapFile();
00275 //   return true;
00276 // }
00277 
00278 
00279 bool EcalElectronicsMapper::makeMapFromVectors( std::vector<int>& orderedFedUnpackList,
00280                                                std::vector<int>& orderedDCCIdList )
00281 {
00282 
00283   // in case as non standard set of DCCId:FedId pairs was provided
00284   if ( orderedFedUnpackList.size() == orderedDCCIdList.size() &&
00285        orderedFedUnpackList.size() > 0)
00286     {
00287       edm::LogInfo("EcalElectronicsMapper") << "DCCIdList/FedUnpackList lists given. Being loaded.";
00288       
00289       std::string correspondence("list of pairs DCCId:FedId :  ");
00290       char           onePair[50];
00291       for (int v=0;  v< ((int)orderedFedUnpackList.size());  v++)        {
00292         myDCCMap_[ orderedDCCIdList[v]  ] = orderedFedUnpackList[v] ;
00293         
00294         sprintf( onePair, "  %d:%d",  orderedDCCIdList[v], orderedFedUnpackList[v]);
00295         std::string                 tmp(onePair);
00296         correspondence += tmp;
00297       }
00298       edm::LogInfo("EcalElectronicsMapper") << correspondence;
00299       
00300     }
00301   else    
00302     {  // default set of DCCId:FedId for ECAL
00303 
00304       edm::LogInfo("EcalElectronicsMapper") << "No input DCCIdList/FedUnpackList lists given for ECAL unpacker"
00305                                             << "(or given with different number of elements). "
00306                                             << " Loading default association DCCIdList:FedUnpackList,"
00307                                             << "i.e.  1:601 ... 53:653,  54:654.";
00308       
00309       for (unsigned int v=1; v<=54; v++)        {
00310         myDCCMap_[ v ] = (v+600) ;   }
00311     }
00312 
00313   return true;
00314 }
00315 
00316 
00317 std::ostream &operator<< (std::ostream& o, const EcalElectronicsMapper &aMapper_) {
00318   //print class information
00319   o << "---------------------------------------------------------";
00320 
00321   if(aMapper_.pathToMapFile_.size() < 1){
00322     o << "No correct input for DCC map has been given yet...";
00323   }
00324   else{
00325     o << "DCC Map (Map file: " << aMapper_.pathToMapFile_ << " )" << "SM id\t\tDCCid ";
00326 
00327     //get DCC map and iterator
00328     std::map<unsigned int ,unsigned int > aMap;
00329     aMap=aMapper_.myDCCMap_;
00330     std::map<unsigned int ,unsigned int >::iterator iter;
00331 
00332     //print info contained in map
00333     for(iter = aMap.begin(); iter != aMap.end(); iter++)
00334       o << iter->first << "\t\t" << iter->second;
00335   }
00336 
00337   o << "---------------------------------------------------------";
00338   return o;
00339 }
00340 
00341   
00342 
00343 unsigned int EcalElectronicsMapper::computeUnfilteredFEBlockLength(){
00344 
00345   return ((numbXtalTSamples_-2)/4+1)*25+1; 
00346 
00347 }
00348 
00349 
00350 unsigned int EcalElectronicsMapper::computeEBTCCBlockLength(){
00351 
00352   unsigned int nTT=68;
00353   unsigned int tf;
00354           
00355   //TCC block size: header (8 bytes) + 17 words with 4 trigger primitives (17*8bytes)
00356   if( (nTT*numbTriggerTSamples_)<4 || (nTT*numbTriggerTSamples_)%4 ) tf=1;  
00357   else tf=0;
00358     
00359   return 1 + ((nTT*numbTriggerTSamples_)/4) + tf ;
00360 
00361 }
00362 
00363 unsigned int EcalElectronicsMapper::computeEETCCBlockLength(){
00364   //Todo : implement multiple tt samples for the endcap
00365   return 9;  
00366 
00367 }
00368 
00369 bool EcalElectronicsMapper::isTCCExternal(unsigned int TCCId){
00370   if(
00371      (NUMB_TCC_EE_MIN_EXT_MIN <= TCCId && TCCId<=NUMB_TCC_EE_MIN_EXT_MAX) ||
00372      (NUMB_TCC_EE_PLU_EXT_MIN <= TCCId && TCCId<=NUMB_TCC_EE_PLU_EXT_MAX)
00373      ) return true;
00374   else return false;
00375 }
00376 
00377 unsigned int EcalElectronicsMapper::getDCCId(unsigned int aSMId_) const{
00378   //get iterator for SM id
00379   std::map<unsigned int ,unsigned int>::const_iterator it = myDCCMap_.find(aSMId_);
00380 
00381   //check if SMid exists and return DCC id
00382   if(it!= myDCCMap_.end()) return it->second;
00383  
00384   //error return
00385   if( ! DCCDataUnpacker::silentMode_ ){
00386     edm::LogError("IncorrectMapping") << "DCC requested for SM id: " << aSMId_ << " not found";
00387   }
00388   return 0;
00389 }
00390 
00391 
00392 unsigned int EcalElectronicsMapper::getSMId(unsigned int aDCCId_) const {
00393   //get iterator map
00394   std::map<unsigned int ,unsigned int>::const_iterator it;
00395 
00396   //try to find SM id for given DCC id
00397   for(it = myDCCMap_.begin(); it != myDCCMap_.end(); it++)
00398     if(it->second == aDCCId_) 
00399       return it->first;
00400 
00401   //error return
00402   if( ! DCCDataUnpacker::silentMode_ ){
00403     edm::LogError("IncorrectMapping") << "SM requested DCC id: " << aDCCId_ << " not found";
00404   }
00405   return 0;
00406 }
00407 
00408 
00409 
00410 
00411 void EcalElectronicsMapper::fillMaps(){
00412  
00413   for( int smId=1 ; smId<= 54; smId++){
00414 
00415     
00416     // Fill EB arrays  
00417     if( smId > 9 && smId < 46 ){
00418          
00419       for(int feChannel =1; feChannel<=68; feChannel++){
00420                    
00421         unsigned int tccId = smId + TCCID_SMID_SHIFT_EB;
00422                   
00423         // Builds Ecal Trigger Tower Det Id 
00424 
00425         unsigned int rawid = (mappingBuilder_->getTrigTowerDetId(tccId, feChannel)).rawId();
00426         EcalTrigTowerDetId * ttDetId = new EcalTrigTowerDetId(rawid);
00427         ttDetIds_[tccId-1][feChannel-1] = ttDetId;
00428         EcalElectronicsId * ttEleId = new EcalElectronicsId(smId, feChannel, 1, 1);
00429         ttEleIds_[tccId-1][feChannel-1] = ttEleId;
00430         EcalTriggerPrimitiveDigi * tp     = new EcalTriggerPrimitiveDigi(*ttDetId);
00431         tp->setSize(numbTriggerTSamples_);
00432         for(unsigned int i=0;i<numbTriggerTSamples_;i++){
00433           tp->setSample( i, EcalTriggerPrimitiveSample(0) );
00434         }
00435         ttTPIds_[tccId-1][feChannel-1]  = tp;
00436 
00437         // build pseudostrip input data digi
00438         for(int ps=1; ps<=5; ps++){
00439             psInput_[tccId-1][feChannel-1][ps-1]= new EcalPseudoStripInputDigi( EcalTriggerElectronicsId(tccId, feChannel, ps, 1) );
00440             psInput_[tccId-1][feChannel-1][ps-1]->setSize(1);
00441             psInput_[tccId-1][feChannel-1][ps-1]->setSample( 0, EcalPseudoStripInputSample(0) );
00442         }
00443 
00444         // Buil SRP Flag
00445         srFlags_[smId-1][feChannel-1].push_back(new EBSrFlag(*ttDetId,0));
00446 
00447         //only one element for barrel: 1-to-1 correspondance between
00448         //DCC channels and EB trigger tower:
00449         assert(srFlags_[smId-1][feChannel-1].size()==1);
00450  
00451         for(unsigned int stripId =1; stripId<=5; stripId++){
00452                     
00453           for(unsigned int xtalId =1;xtalId<=5;xtalId++){
00454                    
00455               EcalElectronicsId eid(smId,feChannel,stripId,xtalId);
00456               EBDetId * detId = new EBDetId( (mappingBuilder_->getDetId(eid)).rawId());
00457               xtalDetIds_[smId-1][feChannel-1][stripId-1][xtalId-1] = detId;
00458                          
00459            } // close loop over xtals
00460         }// close loop over strips
00461                                   
00462       }// close loop over fechannels
00463                 
00464     }//close loop over sm ids in the EB
00465     // Fill EE arrays (Todo : waiting SC correction)
00466     
00467     else{
00468          
00469         std::vector<unsigned int> * pTCCIds = mapSmIdToTccIds_[smId];
00470         std::vector<unsigned int>::iterator it;
00471                 
00472         for(it= pTCCIds->begin(); it!= pTCCIds->end(); it++){
00473                         
00474           unsigned int tccId = *it;
00475           
00476           // creating arrays of pointers for trigger objects
00477           for(unsigned int towerInTCC =1; towerInTCC <= numChannelsInDcc_[smId-1]; towerInTCC++){
00478               
00479               // Builds Ecal Trigger Tower Det Id 
00480               EcalTrigTowerDetId ttDetId = mappingBuilder_->getTrigTowerDetId(tccId, towerInTCC);
00481               
00482               ttDetIds_[tccId-1][towerInTCC-1] = new EcalTrigTowerDetId(ttDetId.rawId());
00483               EcalTriggerPrimitiveDigi * tp   = new EcalTriggerPrimitiveDigi(ttDetId);
00484               tp->setSize(numbTriggerTSamples_);
00485               for(unsigned int i=0;i<numbTriggerTSamples_;i++){
00486                   tp->setSample( i, EcalTriggerPrimitiveSample(0) );
00487               }
00488               
00489               ttTPIds_[tccId-1][towerInTCC-1]  = tp;
00490               
00491               // build pseudostrip input data digi
00492                for(int ps=1; ps<=5; ps++){
00493                    psInput_[tccId-1][towerInTCC-1][ps-1]= new EcalPseudoStripInputDigi( EcalTriggerElectronicsId(tccId, towerInTCC, ps, 1) );
00494                    psInput_[tccId-1][towerInTCC-1][ps-1]->setSize(1);
00495                    psInput_[tccId-1][towerInTCC-1][ps-1]->setSample( 0, EcalPseudoStripInputSample(0) );
00496                }
00497               
00498           }
00499         }
00500         
00501         // creating arrays of pointers for digi objects
00502         for(unsigned int feChannel = 1; feChannel <= numChannelsInDcc_[smId-1]; feChannel++){
00503           
00504           // to avoid gap in CCU_id's
00505           if((smId==SECTOR_EEM_CCU_JUMP   || smId== SECTOR_EEP_CCU_JUMP) &&
00506              (MIN_CCUID_JUMP <= feChannel && feChannel <=MAX_CCUID_JUMP )
00507              ) continue;
00508           
00509           std::vector<EcalScDetId> scDetIds = mappingBuilder_->getEcalScDetId(smId,feChannel);
00510           // scDetIds_[smId-1][feChannel-1] = new EcalScDetId(scDetId.rawId());
00511           scEleIds_[smId-1][feChannel-1] = new EcalElectronicsId(smId,feChannel,1,1);
00512 
00513           for(size_t i = 0; i < scDetIds.size(); ++i){
00514             // std::cout << __FILE__ << ":" << __LINE__ << ": "
00515             //            << "(DCC,RU) = (" <<  smId << "," << feChannel
00516             //            << ") -> " << scDetIds[i] << "\n";
00517             
00518             srFlags_[smId-1][feChannel-1].push_back(new EESrFlag( EcalScDetId( scDetIds[i].rawId() ) , 0 ));
00519           }
00520           //usually only one element 1 DCC channel <-> 1 SC
00521           //in few case two or three elements: partial SCs grouped. 
00522           assert(srFlags_[smId-1][feChannel-1].size()<=3);
00523           
00524           std::vector<DetId> ecalDetIds = mappingBuilder_->dccTowerConstituents(smId,feChannel);
00525           std::vector<DetId>::iterator it;
00526                                   
00527           //EEDetIds        
00528           for(it = ecalDetIds.begin(); it!= ecalDetIds.end(); it++){
00529             
00530             EcalElectronicsId ids = mappingBuilder_->getElectronicsId((*it));
00531             
00532             int stripId    = ids.stripId();
00533             int xtalId     = ids.xtalId();
00534             
00535             EEDetId * detId = new EEDetId((*it).rawId());
00536             xtalDetIds_[smId-1][feChannel-1][stripId-1][xtalId-1] = detId;
00537           }// close loop over tower constituents
00538           
00539         }// close loop over  FE Channels                
00540         
00541     }// closing loop over sm ids in EE
00542         
00543   }
00544 
00545 
00546   // developing mapping for pseudostrip input data: (tccId,psNumber)->(tccId,towerId,psId)
00547   // initializing array for pseudostrip data
00548   short numStripInTT[EcalTriggerElectronicsId::MAX_TCCID][EcalTrigTowerDetId::kEBTowersPerSM];
00549   for (int tccId=0; tccId<EcalTriggerElectronicsId::MAX_TCCID; tccId++){
00550       for (int tt=0; tt<EcalTrigTowerDetId::kEBTowersPerSM; tt++){
00551           numStripInTT[tccId][tt]=-2;} }
00552 
00553   
00554   // assumption: if ps_max is the largest pseudostripId within a trigger tower
00555   // all the pseudostrip 1 ...  ps_max are actually present
00556   std::vector<DetId>::iterator theTCCConstituent;
00557   for(int tccId = 0; tccId< EcalTriggerElectronicsId::MAX_TCCID ; tccId++)
00558   {
00559       
00560       // loop over all constituents of a TCC and collect
00561       // the largest pseudostripId within each trigger tower
00562       std::vector<DetId> tccConstituents = mappingBuilder_->tccConstituents(tccId+1);
00563       
00564       for (theTCCConstituent  = tccConstituents.begin();
00565            theTCCConstituent != tccConstituents.end();
00566            theTCCConstituent++)
00567       {
00568 
00569           int towerId = ( mappingBuilder_->getTriggerElectronicsId(*theTCCConstituent) ) .ttId();
00570           int ps    = ( mappingBuilder_->getTriggerElectronicsId(*theTCCConstituent) ) .pseudoStripId();
00571           if( ps > numStripInTT[tccId][towerId-1]) numStripInTT[tccId][towerId-1] = ps;
00572 
00573           //std::cout << "tccId: " << (tccId+1) << "    towerId: " << towerId
00574           // << "    ps: " << ps << "    numStripInTT: " << numStripInTT[tccId][towerId-1] << std::endl;
00575           
00576       }// loop on TCC constituents
00577 
00578   }// loop on TCC's
00579 
00580   
00581   int   psCounter;
00582   for (int tccId=0; tccId<EcalTriggerElectronicsId::MAX_TCCID; tccId++)
00583   {
00584       // resetting pseudostrip counter at each new TCC
00585       psCounter=0;
00586       for (int towerId=0; towerId < EcalTrigTowerDetId::kEBTowersPerSM; towerId++)
00587       {
00588           // if there's not a given towerId, numStripInTT==-1
00589           for (int ps=0; ps<numStripInTT[tccId][towerId]; ps++)
00590           {
00591               tTandPs_[tccId][psCounter][0]=towerId+1;
00592               tTandPs_[tccId][psCounter][1]=ps+1;
00593               psCounter++;
00594           } // loop on TCC's
00595       } // loop on towers in TCC
00596   } // loop in ps in tower
00597   
00598   
00599 //   for (int tccId=0; tccId<EcalTriggerElectronicsId::MAX_TCCID; tccId++) {
00600 //       for (int psCounter=0; psCounter<EcalTrigTowerDetId::kEBTowersPerSM*5; psCounter++) {
00601 //           std::cout << "tccId: " << (tccId+1) << "    counter: " << (psCounter+1)
00602 //                     << " tt: " << tTandPs_[tccId][psCounter][0]
00603 //                     << " ps: " << tTandPs_[tccId][psCounter][1]
00604 //                     << std::endl;
00605 //       } } 
00606   
00607   
00608   
00609   // Note:
00610   // for TCC 48 in EE, pseudostrip data in the interval:
00611   // + 1-30 is good pseudostrip data
00612   // + 31-42 is a duplication of the last 12 ps of the previous block, and needs be ignored
00613   // + 43-60 is further good pseudostrip data
00614   
00615   for (int tcc=EcalTriggerElectronicsId::MIN_TCCID_EEM; tcc<=EcalTriggerElectronicsId::MAX_TCCID_EEM; tcc++)
00616   {
00617       int tccId=tcc-1;
00618       short tTandPs_tmp[18][2];
00619 
00620       // store entries _after_ the pseudostrip data which gets duplicated
00621       for (int psCounter=30; psCounter<48; psCounter++) {
00622           tTandPs_tmp[psCounter-30][0] = tTandPs_[tccId][psCounter][0];
00623           tTandPs_tmp[psCounter-30][1] = tTandPs_[tccId][psCounter][1]; }
00624       
00625       // duplication
00626       for (int psCounter=18; psCounter<30; psCounter++) {
00627           tTandPs_[tccId][psCounter+12][0] = tTandPs_[tccId][psCounter][0];
00628           tTandPs_[tccId][psCounter+12][1] = tTandPs_[tccId][psCounter][1]; }
00629       
00630       // append stoed
00631       for (int psCounter=42; psCounter<60; psCounter++) {
00632           tTandPs_[tccId][psCounter][0] = tTandPs_tmp[psCounter-42][0];
00633           tTandPs_[tccId][psCounter][1] = tTandPs_tmp[psCounter-42][1]; }
00634       
00635   }// loop on EEM TCC's
00636 
00637   
00638   for (int tcc=EcalTriggerElectronicsId::MIN_TCCID_EEP; tcc<=EcalTriggerElectronicsId::MAX_TCCID_EEP; tcc++)
00639   {
00640       int tccId=tcc-1;
00641       short tTandPs_tmp[18][2];
00642       
00643       // store entries _after_ the pseudostrip data which gets duplicated
00644       for (int psCounter=30; psCounter<48; psCounter++) {
00645           tTandPs_tmp[psCounter-30][0] = tTandPs_[tccId][psCounter][0];
00646           tTandPs_tmp[psCounter-30][1] = tTandPs_[tccId][psCounter][1]; }
00647       
00648       // duplication
00649       for (int psCounter=18; psCounter<30; psCounter++) {
00650           tTandPs_[tccId][psCounter+12][0] = tTandPs_[tccId][psCounter][0];
00651           tTandPs_[tccId][psCounter+12][1] = tTandPs_[tccId][psCounter][1]; }
00652       
00653       // append stoed
00654       for (int psCounter=42; psCounter<60; psCounter++) {
00655           tTandPs_[tccId][psCounter][0] = tTandPs_tmp[psCounter-42][0];
00656           tTandPs_[tccId][psCounter][1] = tTandPs_tmp[psCounter-42][1]; }
00657       
00658   }// loop on EEP TCC's
00659 
00660   
00661   //for (int tccId=0; tccId<EcalTriggerElectronicsId::MAX_TCCID; tccId++) {
00662   //for (int psCounter=0; psCounter<EcalTrigTowerDetId::kEBTowersPerSM*5; psCounter++) {
00663   //std::cout << "AF tccId: " << (tccId+1) << "    counter: " << (psCounter+1)
00664   //<< " tt: " << tTandPs_[tccId][psCounter][0]
00665   //<< " ps: " << tTandPs_[tccId][psCounter][1]
00666   //<< std::endl;
00667 // } }
00668 
00669 }
00670 
00671 
00672 void EcalElectronicsMapper::setupGhostMap()
00673 {
00674   // number of 'ghost' VFEs
00675   const int n = 44;
00676   
00677   // here is a list of all 'ghost' VFEs
00678   // in format {FED, CCU, VFE}
00679   const struct {int FED, CCU, VFE;} v[n] = {
00680     {601, 10, 5},
00681     {601, 34, 3},
00682     {601, 34, 4},
00683     {601, 34, 5},
00684     {602, 32, 5},
00685     {603, 12, 5},
00686     {603, 30, 5},
00687     {604, 12, 5},
00688     {604, 30, 5},
00689     {605, 32, 5},
00690     {606, 10, 5},
00691     {606, 34, 3},
00692     {606, 34, 4},
00693     {606, 34, 5},
00694     {608, 27, 3},
00695     {608, 27, 4},
00696     {608, 27, 5},
00697     {608,  3, 3},
00698     {608,  3, 4},
00699     {608,  3, 5},
00700     {608, 30, 5},
00701     {608,  6, 5},
00702     {646, 10, 5},
00703     {646, 34, 3},
00704     {646, 34, 4},
00705     {646, 34, 5},
00706     {647, 32, 5},
00707     {648, 12, 5},
00708     {648, 30, 5},
00709     {649, 12, 5},
00710     {649, 30, 5},
00711     {650, 32, 5},
00712     {651, 10, 5},
00713     {651, 34, 3},
00714     {651, 34, 4},
00715     {651, 34, 5},
00716     {653, 27, 3},
00717     {653, 27, 4},
00718     {653, 27, 5},
00719     {653,  3, 3},
00720     {653,  3, 4},
00721     {653,  3, 5},
00722     {653, 30, 5},
00723     {653,  6, 5}
00724   };
00725   
00726   for (int i = 0; i < n; ++i)
00727     ghost_[v[i].FED][v[i].CCU][v[i].VFE] = true;
00728 }
00729 
00730 bool EcalElectronicsMapper::isGhost(const int FED, const int CCU, const int VFE)
00731 {
00732   if (ghost_.find(FED) == ghost_.end())
00733     return false;
00734   
00735   if (ghost_[FED].find(CCU) == ghost_[FED].end())
00736     return false;
00737   
00738   if (ghost_[FED][CCU].find(VFE) == ghost_[FED][CCU].end())
00739     return false;
00740   
00741   return true;
00742 }
00743 
00744 // number of readout channels (TT in EB, SC in EE) in a DCC
00745 const unsigned int  EcalElectronicsMapper::numChannelsInDcc_[NUMB_SM] = {34,32,33,33,32,34,33,41,33,    // EE -
00746                                                                           68,68,68,68,68,68,68,68,68,68, // EB-
00747                                                                           68,68,68,68,68,68,68,68,
00748                                                                           68,68,68,68,68,68,68,68,68,68, // EB+
00749                                                                           68,68,68,68,68,68,68,68,
00750                                                                           34,32,33,33,32,34,33,41,33};   // EE+