CMS 3D CMS Logo

EcalElectronicsMapper.cc

Go to the documentation of this file.
00001 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00002 #include <EventFilter/EcalRawToDigiDev/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/EcalRawToDigiDev/interface/DCCDataUnpacker.h>
00007 
00008 EcalElectronicsMapper::EcalElectronicsMapper( uint numbXtalTSamples, uint numbTriggerTSamples)
00009 : pathToMapFile_(""),
00010 numbXtalTSamples_(numbXtalTSamples),
00011 numbTriggerTSamples_(numbTriggerTSamples),
00012 mappingBuilder_(0)
00013 
00014 {
00015         
00016   
00017   // Reset Arrays
00018   for(uint sm=0; sm < NUMB_SM; sm++){
00019     for(uint fe=0; fe< NUMB_FE; fe++){
00020           
00021       for(uint strip=0; strip<NUMB_STRIP;strip++){
00022         for(uint xtal=0; xtal<NUMB_XTAL;xtal++){
00023                     
00024           //Reset DFrames and xtalDetIds
00025           xtalDetIds_[sm][fe][strip][xtal]=0;
00026         }
00027       }
00028       //Reset SC Det Ids
00029       scDetIds_[sm][fe]=0;
00030       scEleIds_[sm][fe]=0;
00031       srFlags_[sm][fe]=0;
00032     }
00033   }
00034   
00035   
00036   //Reset TT det Ids
00037   for( uint tccid=0; tccid < NUMB_TCC; tccid++){
00038     for(uint tpg =0; tpg<NUMB_FE;tpg++){
00039       ttDetIds_[tccid][tpg]=0;
00040       ttTPIds_[tccid][tpg]=0;
00041     }
00042   }
00043 
00044   
00045 
00046   //Fill map sm id to tcc ids
00047   std::vector<uint> * ids;
00048   ids = new std::vector<uint>;
00049   ids->push_back(1); ids->push_back(18);ids->push_back(19);ids->push_back(36);
00050   mapSmIdToTccIds_[1]= ids;
00051                 
00052   ids = new std::vector<uint>;
00053   ids->push_back(2); ids->push_back(3);ids->push_back(20);ids->push_back(21);
00054   mapSmIdToTccIds_[2]= ids;
00055                 
00056   ids = new std::vector<uint>;
00057   ids->push_back(4); ids->push_back(5);ids->push_back(22);ids->push_back(23);
00058   mapSmIdToTccIds_[3]= ids;
00059                 
00060   ids = new std::vector<uint>;
00061   ids->push_back(6); ids->push_back(7);ids->push_back(24);ids->push_back(25);
00062   mapSmIdToTccIds_[4]= ids;
00063                 
00064   ids = new std::vector<uint>;
00065   ids->push_back(8); ids->push_back(9);ids->push_back(26);ids->push_back(27);
00066   mapSmIdToTccIds_[5]= ids;
00067                 
00068   ids = new std::vector<uint>;
00069   ids->push_back(10); ids->push_back(11);ids->push_back(28);ids->push_back(29);
00070   mapSmIdToTccIds_[6]= ids;
00071                 
00072   ids = new std::vector<uint>;
00073   ids->push_back(12); ids->push_back(13);ids->push_back(30);ids->push_back(31);
00074   mapSmIdToTccIds_[7]= ids;
00075                 
00076   ids = new std::vector<uint>;
00077   ids->push_back(14); ids->push_back(15);ids->push_back(32);ids->push_back(33);
00078   mapSmIdToTccIds_[8]= ids;
00079                 
00080   ids = new std::vector<uint>;
00081   ids->push_back(16); ids->push_back(17);ids->push_back(34);ids->push_back(35);
00082   mapSmIdToTccIds_[9]= ids;
00083                 
00084   ids = new std::vector<uint>;
00085   ids->push_back(73); ids->push_back(90);ids->push_back(91);ids->push_back(108);
00086   mapSmIdToTccIds_[46]= ids;
00087                 
00088   ids = new std::vector<uint>;
00089   ids->push_back(74); ids->push_back(75);ids->push_back(92);ids->push_back(93);
00090   mapSmIdToTccIds_[47]= ids;
00091                 
00092   ids = new std::vector<uint>;
00093   ids->push_back(76); ids->push_back(77);ids->push_back(94);ids->push_back(95);
00094   mapSmIdToTccIds_[48]= ids;
00095                 
00096   ids = new std::vector<uint>;
00097   ids->push_back(78); ids->push_back(79);ids->push_back(96);ids->push_back(97);
00098   mapSmIdToTccIds_[49]= ids;
00099                 
00100   ids = new std::vector<uint>;
00101   ids->push_back(80); ids->push_back(81);ids->push_back(98);ids->push_back(99);  
00102   mapSmIdToTccIds_[50]= ids;
00103                  
00104   ids = new std::vector<uint>;
00105   ids->push_back(82); ids->push_back(83);ids->push_back(100);ids->push_back(101);
00106   mapSmIdToTccIds_[51]= ids;
00107                 
00108   ids = new std::vector<uint>;
00109   ids->push_back(84); ids->push_back(85);ids->push_back(102);ids->push_back(103);
00110   mapSmIdToTccIds_[52]= ids;
00111                 
00112   ids = new std::vector<uint>;
00113   ids->push_back(86); ids->push_back(87);ids->push_back(104);ids->push_back(105);
00114   mapSmIdToTccIds_[53]= ids;
00115                 
00116   ids = new std::vector<uint>;
00117   ids->push_back(88); ids->push_back(89);ids->push_back(106);ids->push_back(107);
00118   mapSmIdToTccIds_[54]= ids;
00119         
00120   
00121   //Compute data block sizes
00122   unfilteredFEBlockLength_= computeUnfilteredFEBlockLength();  
00123   ebTccBlockLength_       = computeEBTCCBlockLength();
00124   eeTccBlockLength_       = computeEETCCBlockLength();
00125     
00126 
00127 }
00128 
00129 
00130 EcalElectronicsMapper::~EcalElectronicsMapper(){
00131 
00132 
00133   if( mappingBuilder_ ){ delete mappingBuilder_; }
00134  
00135 
00136   //DETETE ARRAYS
00137   for(uint sm=0; sm < NUMB_SM; sm++){
00138     for(uint fe=0; fe< NUMB_FE; fe++){
00139       for(uint strip=0; strip<NUMB_STRIP;strip++){
00140         for(uint xtal=0; xtal<NUMB_XTAL;xtal++){
00141           if(xtalDetIds_[sm][fe][strip][xtal]){ 
00142             delete xtalDetIds_[sm][fe][strip][xtal]; 
00143           }
00144         }
00145       }
00146 
00147       if(scDetIds_[sm][fe]){ 
00148         delete scDetIds_[sm][fe];
00149         delete scEleIds_[sm][fe];
00150         delete srFlags_[sm][fe];
00151       }
00152 
00153     }
00154  
00155   }
00156   
00157   for( uint tccid=0; tccid < NUMB_TCC; tccid++){
00158     for(uint tpg =0; tpg<NUMB_FE;tpg++){
00159       if(ttDetIds_[tccid][tpg]){ 
00160         delete ttDetIds_[tccid][tpg];
00161         delete ttTPIds_[tccid][tpg];
00162       }
00163     }
00164   }
00165 
00166 
00167   pathToMapFile_.clear();
00168   
00169   
00170   std::map<uint, std::vector<uint> *>::iterator it;
00171   for(it = mapSmIdToTccIds_.begin(); it != mapSmIdToTccIds_.end(); it++ ){ delete (*it).second; }
00172   
00173   mapSmIdToTccIds_.clear();
00174  
00175 }
00176 
00177 void EcalElectronicsMapper::setEcalElectronicsMapping(const EcalElectronicsMapping * m){
00178   mappingBuilder_= m;
00179   fillMaps();
00180 
00181 }
00182 
00183 bool EcalElectronicsMapper::setActiveDCC(uint dccId){
00184    
00185   bool ret(true);
00186         
00187   //Update active dcc and associated smId
00188   dccId_ = dccId;
00189    
00190   smId_  = getSMId(dccId_);
00191         
00192   if(!smId_) ret = false;
00193         
00194   return ret;
00195         
00196  } 
00197  
00198  
00199 bool EcalElectronicsMapper::setDCCMapFilePath(std::string aPath_){
00200 
00201   
00202   //try to open a dccMapFile in the given path
00203   std::ifstream dccMapFile_(aPath_.c_str());
00204 
00205   //if not successful return false
00206   if(!dccMapFile_.is_open()) return false;
00207 
00208   //else close file and accept given path
00209   dccMapFile_.close();
00210   pathToMapFile_ = aPath_;
00211 
00212   return true;
00213 }
00214 
00215 
00216 // bool EcalElectronicsMapper::readDCCMapFile(){
00217 
00218 //   //try to open a dccMapFile in the given path
00219 //   std::ifstream dccMapFile_(pathToMapFile_.c_str());
00220   
00221 //   //if not successful return false
00222 //   if(!dccMapFile_.is_open()) return false;
00223   
00224 //   char lineBuf_[100];
00225 //   uint SMId_,DCCId_;
00226 //   // loop while extraction from file is possible
00227 //   dccMapFile_.getline(lineBuf_,10);       //read line from file
00228 //   while (dccMapFile_.good()) {
00229 //     sscanf(lineBuf_,"%u:%u",&SMId_,&DCCId_);
00230 //     myDCCMap_[SMId_] = DCCId_;
00231 //     dccMapFile_.getline(lineBuf_,10);       //read line from file
00232 //   }
00233   
00234   
00235 //   return true;
00236   
00237 // }
00238 
00239 // bool EcalElectronicsMapper::readDCCMapFile(std::string aPath_){
00240 //   //test if path is good
00241 //   edm::FileInPath eff(aPath_);
00242   
00243 //   if(!setDCCMapFilePath(eff.fullPath())) return false;
00244 
00245 //   //read DCC map file
00246 //   readDCCMapFile();
00247 //   return true;
00248 // }
00249 
00250 
00251 bool EcalElectronicsMapper::makeMapFromVectors( std::vector<int>& orderedFedUnpackList,
00252                                                std::vector<int>& orderedDCCIdList )
00253 {
00254 
00255   // in case as non standard set of DCCId:FedId pairs was provided
00256   if ( orderedFedUnpackList.size() == orderedDCCIdList.size() &&
00257        orderedFedUnpackList.size() > 0)
00258     {
00259       edm::LogInfo("EcalElectronicsMapper") << "DCCIdList/FedUnpackList lists given. Being loaded.";
00260       
00261       std::string correspondence("list of pairs DCCId:FedId :  ");
00262       char           onePair[50];
00263       for (int v=0;  v< ((int)orderedFedUnpackList.size());  v++)       {
00264         myDCCMap_[ orderedDCCIdList[v]  ] = orderedFedUnpackList[v] ;
00265         
00266         sprintf( onePair, "  %d:%d",  orderedDCCIdList[v], orderedFedUnpackList[v]);
00267         std::string                 tmp(onePair);
00268         correspondence += tmp;
00269       }
00270       edm::LogInfo("EcalElectronicsMapper") << correspondence;
00271       
00272     }
00273   else    
00274     {  // default set of DCCId:FedId for ECAL
00275 
00276       edm::LogInfo("EcalElectronicsMapper") << "No input DCCIdList/FedUnpackList lists given for ECAL unpacker"
00277                                             << "(or given with different number of elements). "
00278                                             << " Loading default association DCCIdList:FedUnpackList,"
00279                                             << "i.e.  1:601 ... 53:653,  54:654.";
00280       
00281       for (uint v=1; v<=54; v++)        {
00282         myDCCMap_[ v ] = (v+600) ;   }
00283     }
00284 
00285   return true;
00286 }
00287 
00288 
00289 std::ostream &operator<< (std::ostream& o, const EcalElectronicsMapper &aMapper_) {
00290   //print class information
00291   o << "---------------------------------------------------------";
00292 
00293   if(aMapper_.pathToMapFile_.size() < 1){
00294     o << "No correct input for DCC map has been given yet...";
00295   }
00296   else{
00297     o << "DCC Map (Map file: " << aMapper_.pathToMapFile_ << " )" << "SM id\t\tDCCid ";
00298 
00299     //get DCC map and iterator
00300     std::map<uint ,uint > aMap;
00301     aMap=aMapper_.myDCCMap_;
00302     std::map<uint ,uint >::iterator iter;
00303 
00304     //print info contained in map
00305     for(iter = aMap.begin(); iter != aMap.end(); iter++)
00306       o << iter->first << "\t\t" << iter->second;
00307   }
00308 
00309   o << "---------------------------------------------------------";
00310   return o;
00311 }
00312 
00313   
00314 
00315 uint EcalElectronicsMapper::computeUnfilteredFEBlockLength(){
00316 
00317   return ((numbXtalTSamples_-2)/4+1)*25+1; 
00318 
00319 }
00320 
00321 
00322 uint EcalElectronicsMapper::computeEBTCCBlockLength(){
00323 
00324   uint nTT=68;
00325   uint tf;
00326           
00327   //TCC block size: header (8 bytes) + 17 words with 4 trigger primitives (17*8bytes)
00328   if( (nTT*numbTriggerTSamples_)<4 || (nTT*numbTriggerTSamples_)%4 ) tf=1;  
00329   else tf=0;
00330     
00331   return 1 + ((nTT*numbTriggerTSamples_)/4) + tf ;
00332 
00333 }
00334 
00335 uint EcalElectronicsMapper::computeEETCCBlockLength(){
00336   //Todo : implement multiple tt samples for the endcap
00337   return 9;  
00338 
00339 }
00340 
00341 
00342 uint EcalElectronicsMapper::getDCCId(uint aSMId_) const{
00343   //get iterator for SM id
00344   std::map<uint ,uint>::const_iterator it = myDCCMap_.find(aSMId_);
00345 
00346   //check if SMid exists and return DCC id
00347   if(it!= myDCCMap_.end()) return it->second;
00348  
00349   //error return
00350   if( ! DCCDataUnpacker::silentMode_ ){
00351     edm::LogError("EcalElectronicsMapper") << "DCC requested for SM id: " << aSMId_ << " not found";
00352   }
00353   return 0;
00354 }
00355 
00356 
00357 uint EcalElectronicsMapper::getSMId(uint aDCCId_) const {
00358   //get iterator map
00359   std::map<uint ,uint>::const_iterator it;
00360 
00361   //try to find SM id for given DCC id
00362   for(it = myDCCMap_.begin(); it != myDCCMap_.end(); it++)
00363     if(it->second == aDCCId_) 
00364       return it->first;
00365 
00366   //error return
00367   if( ! DCCDataUnpacker::silentMode_ ){
00368     edm::LogError("EcalEcalElectronicsMapper") << "SM requested DCC id: " << aDCCId_ << " not found";
00369   }
00370   return 0;
00371 }
00372 
00373 
00374 
00375 
00376 void EcalElectronicsMapper::fillMaps(){
00377 
00378  
00379   for( int smId=1 ; smId<= 54; smId++){
00380 
00381     
00382     // Fill EB arrays  
00383     if( smId > 9 && smId < 46 ){
00384          
00385       for(int feChannel =1; feChannel<=68; feChannel++){
00386                    
00387         uint tccId = smId + TCCID_SMID_SHIFT_EB;
00388                   
00389         // Builds Ecal Trigger Tower Det Id 
00390 
00391         uint rawid = (mappingBuilder_->getTrigTowerDetId(tccId, feChannel)).rawId();
00392         EcalTrigTowerDetId * ttDetId = new EcalTrigTowerDetId(rawid);
00393         ttDetIds_[tccId-1][feChannel-1] = ttDetId;
00394         EcalElectronicsId * ttEleId = new EcalElectronicsId(smId, feChannel, 1, 1);
00395         ttEleIds_[tccId-1][feChannel-1] = ttEleId;
00396         EcalTriggerPrimitiveDigi * tp     = new EcalTriggerPrimitiveDigi(*ttDetId);
00397         tp->setSize(numbTriggerTSamples_);
00398         for(uint i=0;i<numbTriggerTSamples_;i++){
00399           tp->setSample( i, EcalTriggerPrimitiveSample(0) );
00400         }
00401         ttTPIds_[tccId-1][feChannel-1]  = tp;   
00402         
00403         // Buil SRP Flag
00404         srFlags_[smId-1][feChannel-1] = new EBSrFlag(*ttDetId,0);
00405  
00406         for(uint stripId =1; stripId<=5; stripId++){
00407                     
00408           for(uint xtalId =1;xtalId<=5;xtalId++){
00409                   
00410               EcalElectronicsId eid(smId,feChannel,stripId,xtalId);
00411               EBDetId * detId = new EBDetId( (mappingBuilder_->getDetId(eid)).rawId());
00412               xtalDetIds_[smId-1][feChannel-1][stripId-1][xtalId-1] = detId;
00413                          
00414            } // close loop over xtals
00415         }// close loop over strips
00416                                 
00417       }// close loop over fechannels
00418                 
00419     }//close loop over sm ids in the EB
00420     // Fill EE arrays (Todo : waiting SC correction)
00421     
00422     else{
00423          
00424         std::vector<uint> * pTCCIds = mapSmIdToTccIds_[smId];
00425         std::vector<uint>::iterator it;
00426                 
00427         for(it= pTCCIds->begin(); it!= pTCCIds->end(); it++){
00428                         
00429           uint tccId = *it;
00430           
00431           // creating arrays of pointers for trigger objects
00432           for(uint towerInTCC =1; towerInTCC <= numChannelsInDcc_[smId-1]; towerInTCC++){
00433               
00434               // Builds Ecal Trigger Tower Det Id 
00435               EcalTrigTowerDetId ttDetId = mappingBuilder_->getTrigTowerDetId(tccId, towerInTCC);
00436               
00437               ttDetIds_[tccId-1][towerInTCC-1] = new EcalTrigTowerDetId(ttDetId.rawId());
00438               EcalTriggerPrimitiveDigi * tp   = new EcalTriggerPrimitiveDigi(ttDetId);
00439               tp->setSize(numbTriggerTSamples_);
00440               for(uint i=0;i<numbTriggerTSamples_;i++){
00441                   tp->setSample( i, EcalTriggerPrimitiveSample(0) );
00442               }
00443               
00444               ttTPIds_[tccId-1][towerInTCC-1]  = tp;
00445               
00446           }
00447         }
00448         
00449 
00450         
00451         // creating arrays of pointers for digi objects
00452         for(uint feChannel = 1; feChannel <= numChannelsInDcc_[smId-1]; feChannel++){
00453 
00454             // to avoid gap in CCU_id's
00455             if((smId==SECTOR_EEM_CCU_JUMP   || smId== SECTOR_EEP_CCU_JUMP) &&
00456                (MIN_CCUID_JUMP <= feChannel && feChannel <=MAX_CCUID_JUMP )
00457                ) continue;
00458             
00459           EcalScDetId scDetId = mappingBuilder_->getEcalScDetId(smId,feChannel);
00460           scDetIds_[smId-1][feChannel-1] = new EcalScDetId(scDetId.rawId());
00461           scEleIds_[smId-1][feChannel-1] = new EcalElectronicsId(smId,feChannel,1,1);
00462           srFlags_[smId-1][feChannel-1]  = new EESrFlag( EcalScDetId( scDetId.rawId() ) , 0 ); 
00463 
00464           std::vector<DetId> ecalDetIds = mappingBuilder_->dccTowerConstituents(smId,feChannel);
00465           std::vector<DetId>::iterator it;
00466                                   
00467           //EEDetIds    
00468           for(it = ecalDetIds.begin(); it!= ecalDetIds.end(); it++){
00469                     
00470           EcalElectronicsId ids = mappingBuilder_->getElectronicsId((*it));
00471                          
00472           int stripId    = ids.stripId();
00473           int xtalId     = ids.xtalId();
00474                  
00475           EEDetId * detId = new EEDetId((*it).rawId());
00476           xtalDetIds_[smId-1][feChannel-1][stripId-1][xtalId-1] = detId;
00477           
00478         }// close loop over tower constituents
00479           
00480         }// close loop over  FE Channels                
00481         
00482     }// closing loop over sm ids in EE
00483         
00484   }
00485   
00486 
00487 }
00488 
00489 // number of readout channels (TT in EB, SC in EE) in a DCC
00490 const uint  EcalElectronicsMapper::numChannelsInDcc_[NUMB_SM] = {34,32,33,33,32,34,33,41,33,    // EE -
00491                                                                  68,68,68,68,68,68,68,68,68,68, // EB-
00492                                                                  68,68,68,68,68,68,68,68,
00493                                                                  68,68,68,68,68,68,68,68,68,68, // EB+
00494                                                                  68,68,68,68,68,68,68,68,
00495                                                                  34,32,33,33,32,34,33,41,33};   // EE+

Generated on Tue Jun 9 17:34:37 2009 for CMSSW by  doxygen 1.5.4