CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CaloOnlineTools/EcalTools/plugins/EcalDigiDisplay.cc

Go to the documentation of this file.
00001 
00013 #include <FWCore/Framework/interface/EDAnalyzer.h>
00014 #include <FWCore/Framework/interface/Event.h>
00015 #include <FWCore/Framework/interface/MakerMacros.h>
00016 #include <FWCore/Framework/interface/ESHandle.h>
00017 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00018 
00019 #include "CaloOnlineTools/EcalTools/plugins/EcalDigiDisplay.h"
00020 #include "CaloOnlineTools/EcalTools/interface/EcalFedMap.h"
00021 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00022 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
00023 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00024 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
00025 
00026 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
00027 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveSample.h"
00028 
00029 #include <iostream>
00030 #include <vector>
00031 #include <set>
00032 #include <map>
00033 
00034 //==========================================================================
00035 EcalDigiDisplay::EcalDigiDisplay(const edm::ParameterSet& ps) {
00036 //=========================================================================
00037   
00038   ebDigiCollection_ = ps.getParameter<std::string>("ebDigiCollection");
00039   eeDigiCollection_ = ps.getParameter<std::string>("eeDigiCollection");
00040   digiProducer_     = ps.getParameter<std::string>("digiProducer");
00041 
00042   requestedFeds_ = ps.getUntrackedParameter<std::vector<int> >("requestedFeds");
00043   requestedEbs_  = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs");
00044 
00045   cryDigi       = ps.getUntrackedParameter<bool>("cryDigi");
00046   ttDigi        = ps.getUntrackedParameter<bool>("ttDigi");
00047   pnDigi      = ps.getUntrackedParameter<bool>("pnDigi");
00048    
00049   mode           = ps.getUntrackedParameter<int>("mode");
00050   listChannels   = ps.getUntrackedParameter<std::vector<int> >("listChannels");
00051   listTowers     = ps.getUntrackedParameter<std::vector<int> >("listTowers");
00052   listPns        = ps.getUntrackedParameter<std::vector<int> >("listPns");
00053 
00054   std::vector<int> listDefaults;
00055   listDefaults.push_back(-1);
00056   requestedFeds_ = ps.getUntrackedParameter<std::vector<int> >("requestedFeds",listDefaults);
00057   bool fedIsGiven = false;
00058   
00059   std::vector<std::string> ebDefaults;
00060   ebDefaults.push_back("none");
00061   requestedEbs_  = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs",ebDefaults);
00062   // FEDs and EBs
00063   if ( requestedFeds_[0] != -1 ) {
00064     edm::LogInfo("EcalDigiDisplay") << "FED id is given! Goining to beginRun! ";
00065     fedIsGiven = true;
00066   }else {
00067     if ( requestedEbs_[0] !="none" ) {
00068       //EB id is given and convert to FED id
00069       requestedFeds_.clear();
00070       fedMap = new EcalFedMap();
00071       for (std::vector<std::string>::const_iterator ebItr = requestedEbs_.begin(); 
00072            ebItr!= requestedEbs_.end();  ++ebItr) {
00073         requestedFeds_.push_back(fedMap->getFedFromSlice(*ebItr));
00074       }
00075       delete fedMap;
00076     } else {
00077       //Select all FEDs in the Event
00078       for ( int i=601; i<655; ++i){
00079         requestedFeds_.push_back(i);
00080       }
00081     }
00082   }
00083 
00084   //Channel list
00085   listChannels = ps.getUntrackedParameter<std::vector<int> >("listChannels",listDefaults);
00086   //Tower list
00087   listTowers     = ps.getUntrackedParameter<std::vector<int> >("listTowers", listDefaults);
00088   
00089   //Consistancy checks:
00090   std::vector<int>::iterator fedIter;
00091   std::vector<int>::iterator intIter;
00092   inputIsOk = true;
00093 
00094   if ( fedIsGiven ) {
00095     for ( fedIter = requestedFeds_.begin(); fedIter!=requestedFeds_.end(); ++fedIter) {  
00096       if ( (*fedIter) < 601 || (*fedIter) > 655 ) {
00097         edm::LogError("EcalDigiDisplay") << " FED value: " << (*fedIter) << " found in requetsedFeds. "
00098                                          << " Valid range is 601-654. Returning.";
00099         inputIsOk = false;
00100         return;
00101       }//Loop over requetsed FEDS
00102     } 
00103   }
00104   bool barrelSM  = false;  
00105   //Loop over and Check if Barrel SM is picked up
00106   for (fedIter = requestedFeds_.begin(); fedIter!=requestedFeds_.end(); ++fedIter) {
00107     if ( (*fedIter) > 609 && (*fedIter) < 646 && inputIsOk )      // if EB SM is being picked up
00108       barrelSM = true;
00109   }
00110   
00111   if ( barrelSM ) {
00112     if ( cryDigi ) {
00113     // Check with channels in Barrel
00114       for (intIter = listChannels.begin(); intIter != listChannels.end(); intIter++)  {  
00115         if ( ((*intIter) < 1) ||  (1700 < (*intIter)) )       {  
00116           edm::LogError("EcalDigiDisplay") << " ic value: " << (*intIter) << " found in listChannels. "
00117                                            << " Valid range is 1-1700. Returning.";
00118           inputIsOk = false;
00119           return;
00120         }
00121       }
00122     }
00123     //Check with Towers in Barrel
00124     if ( ttDigi ) {
00125       for (intIter = listTowers.begin(); intIter != listTowers.end(); intIter++) {
00126         
00127         if ( ((*intIter) < 1) ||  (70 < (*intIter)) )       {  
00128           edm::LogError("EcalDigiDisplay") << " TT value: " << (*intIter) << " found in listTowers. "
00129                                            << " Valid range for EB SM is 1-70. Returning.";
00130           inputIsOk = false;
00131           return;
00132         }
00133       }
00134     }
00135   }else  //if EE DCC is being picked up  
00136     if (ttDigi) {
00137       //Check with Towers in Endcap
00138       for (intIter = listTowers.begin(); intIter != listTowers.end(); intIter++) { 
00139         if ( (*intIter) > 34 )       { 
00140           edm::LogError("EcalDigiDisplay") << " TT value: " << (*intIter) << " found in listTowers. "
00141                                            << " Valid range for EE DCC is 1-34. Returning.";
00142           inputIsOk = false;
00143           return;
00144         }
00145       }
00146     }
00147 
00148   //PNs
00149   listPns     = ps.getUntrackedParameter<std::vector<int> >("listPns",listDefaults);
00150   /*
00151   if ( listPns[0] != -1 ) pnDigi = true;
00152   else {
00153     listPns.clear();
00154     for ( int i=1; i < 11; ++i ) {
00155       listPns.push_back(i);
00156     }
00157   }
00158   */
00159   if ( pnDigi ) {
00160     for (intIter = listPns.begin(); intIter != listPns.end(); intIter++) {
00161       if ( ((*intIter) < 1) ||  (10 < (*intIter)) )       {  
00162         edm::LogError("EcalDigiDisplay") << " Pn number : " << (*intIter) << " found in listPns. "
00163                                          << " Valid range is 1-10. Returning.";
00164         inputIsOk = false;
00165         return;
00166       }
00167     }
00168   }
00169 }
00170 //=========================================================================
00171 EcalDigiDisplay::~EcalDigiDisplay() {
00172 //=========================================================================
00173   //delete *;
00174 }
00175     
00176 //========================================================================
00177 void EcalDigiDisplay::beginRun(edm::Run const &, edm::EventSetup const& c) {
00178 //========================================================================
00179   edm::LogInfo("EcalDigiDisplay") << "entering beginRun! ";
00180 
00181   edm::ESHandle<EcalElectronicsMapping> elecHandle;
00182     c.get<EcalMappingRcd>().get(elecHandle);
00183   ecalElectronicsMap_ = elecHandle.product();
00184 }
00185 
00186 //========================================================================
00187 void EcalDigiDisplay::analyze( edm::Event const & e, edm::EventSetup const & c) {
00188 //========================================================================
00189 
00190   if (!inputIsOk) return;
00191   
00192   //Get DCC headers
00193   edm::Handle<EcalRawDataCollection> dccHeader;
00194   try {
00195     e.getByLabel(digiProducer_,dccHeader);
00196   } catch (cms::Exception& ex) {
00197     edm::LogError("EcalDigiUnpackerModule") << "Can't get DCC Headers!";
00198   }
00199     
00200   //
00201   bool ebDigisFound = false;
00202   bool eeDigisFound = false;
00203   bool pnDigisFound = false;
00204   // retrieving crystal data from Event
00205   edm::Handle<EBDigiCollection>  eb_digis;    
00206   try {
00207     e.getByLabel(digiProducer_,ebDigiCollection_, eb_digis);
00208     if ( eb_digis->size() != 0 )
00209       ebDigisFound = true;
00210   } catch (cms::Exception& ex) {
00211     edm::LogError("EcalDigiUnpackerModule") << "EB Digis were not found!";
00212   }
00213   
00214   //
00215   edm::Handle<EEDigiCollection>  ee_digis;    
00216   try {
00217     e.getByLabel(digiProducer_,eeDigiCollection_, ee_digis);
00218     if ( ee_digis->size() != 0 )
00219       eeDigisFound = true;
00220   } catch (cms::Exception& ex) {
00221     edm::LogError("EcalDigiUnpackerModule") << "EE Digis were not found!";
00222   }
00223   
00224   // retrieving crystal PN diodes from Event
00225   edm::Handle<EcalPnDiodeDigiCollection>  pn_digis;
00226   try {
00227     e.getByLabel(digiProducer_, pn_digis);
00228     if ( pn_digis->size() != 0)
00229       pnDigisFound = true;
00230   } catch (cms::Exception& ex) {
00231     edm::LogError("EcalDigiUnpackerModule") << "PNs were not found!";
00232   }
00233 
00234   //=============================
00235   //Call for funcitons
00236   //=============================
00237   if ( cryDigi || ttDigi ) {
00238     if ( ebDigisFound )
00239       readEBDigis(eb_digis, mode);
00240     if ( eeDigisFound )
00241       readEEDigis(ee_digis, mode);
00242     if ( !(ebDigisFound || eeDigisFound) ) {
00243       edm::LogWarning("EcalDigiUnpackerModule") << "No Digis were found! Returning..";
00244       return;
00245     }
00246   }
00247   if ( pnDigi ) {
00248     if (pnDigisFound )
00249       readPNDigis(pn_digis, mode);
00250   }
00251 }
00252 
00254 // FUNCTIONS
00256 
00257 void EcalDigiDisplay::readEBDigis (edm::Handle<EBDigiCollection> digis, int Mode) {
00258 
00259   for ( EBDigiCollection::const_iterator digiItr= digis->begin();digiItr != digis->end(); 
00260         ++digiItr ) {           
00261 
00262     EBDetId detId = EBDetId((*digiItr).id());
00263     EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(detId);
00264 
00265     int FEDid = elecId.dccId() + 600;
00266     std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid); 
00267     if (fedIter ==  requestedFeds_.end()) continue;
00268 
00269     int ic = EBDetId((*digiItr).id()).ic();
00270     int tt = EBDetId((*digiItr).id()).tower().iTT();
00271 
00272     //Check if Mode is set 1 or 2 
00273     if ( Mode ==1 ) {
00274       edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay]  digi cry collection size " << digis->size();
00275       edm::LogInfo("EcalDigiDisplay") << "                       [EcalDigiDisplay]  dumping first " << listChannels[0] << " crystals\n";
00276       //It will break if all required digis are dumpped
00277       if( ic  > listChannels[0]) continue;  
00278     } else if  ( Mode==2 ) {
00279 
00280       std::vector<int>::iterator icIterCh;
00281       std::vector<int>::iterator icIterTt;
00282       icIterCh = find(listChannels.begin(), listChannels.end(), ic);
00283       icIterTt = find(listTowers.begin(), listTowers.end(), tt);
00284       if (icIterCh == listChannels.end() && icIterTt == listTowers.end() ) continue;   
00285       edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay]  digi cry collection size " << digis->size();
00286     } else {
00287       edm::LogInfo("EcalDigiDisplay") << "[EcalDigiDisplay] parameter mode set to: " << Mode
00288                                       << ". Only mode 1 and 2 are allowed. Returning...";
00289       inputIsOk = false;
00290       return;
00291     }
00292     std::cout << "FEDID: " << FEDid << std::endl;
00293     std::cout << "Tower: " << EBDetId((*digiItr).id()).tower().iTT()
00294               <<" ic-cry: " 
00295               << EBDetId((*digiItr).id()).ic() << " i-phi: " 
00296               << EBDetId((*digiItr).id()).iphi() << " j-eta: " 
00297               << EBDetId((*digiItr).id()).ieta() << std::endl;
00298     //Get Samples
00299     for ( unsigned int i=0; i< (*digiItr).size() ; ++i ) {
00300       EBDataFrame df( *digiItr );
00301       if (!(i%3)  )  std::cout << "\n\t";
00302       std::cout << "sId: " << (i+1) << " " <<  df.sample(i) << "\t";
00303     } 
00304     std::cout << " " << std::endl;
00305   }
00306 }
00307 
00308 //Function for EE Digis
00309 void EcalDigiDisplay::readEEDigis (edm::Handle<EEDigiCollection> digis, int Mode) {
00310 
00311   //For Endcap so far works only  Mode 2
00312   if ( Mode!=2 ) {
00313     std::cout << "For Endcap mode needs to be set to 2" << std::endl;
00314     return;
00315   }
00316   
00317   for ( EEDigiCollection::const_iterator digiItr= digis->begin();digiItr != digis->end(); 
00318         ++digiItr ) {           
00319     
00320     //Make sure that digis are form requested place
00321     EEDetId detId = EEDetId((*digiItr).id());
00322     EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(detId);
00323 
00324     int FEDid = elecId.dccId() + 600;
00325     std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
00326     if (fedIter ==  requestedFeds_.end()) continue;
00327 
00328     edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay]  digi cry collection size " << digis->size();
00329     
00330     int crystalId = 10000 * FEDid + 100 * elecId.towerId() + 5 * (elecId.stripId()-1)+elecId.xtalId();
00331     int chId = elecId.towerId();    // this is a channel in Endcap DCC, sometimes also called as Super Crystal
00332 
00333     std::vector<int>::iterator icIterCh;
00334     std::vector<int>::iterator icIterTt;
00335     icIterCh = find(listChannels.begin(), listChannels.end(), crystalId);
00336     icIterTt = find(listTowers.begin(), listTowers.end(), chId);
00337     if ( icIterCh == listChannels.end() &&  icIterTt == listTowers.end() ) continue; 
00338     
00339     std::cout << "FEDID: " << FEDid << std::endl;
00340     std::cout << "Tower: " << elecId.towerId()    
00341               << "crystalId: " 
00342               << crystalId << " i-x: " 
00343               << EEDetId((*digiItr).id()).ix() << " j-y: " 
00344               << EEDetId((*digiItr).id()).iy() << std::endl;
00345     
00346     //Get samples 
00347     for ( unsigned int i=0; i< (*digiItr).size() ; ++i ) {
00348       EEDataFrame df( *digiItr );
00349       if (!(i%3)  )  std::cout << "\n\t";
00350       std::cout << "sId: " << (i+1) << " " <<  df.sample(i) << "\t";
00351     }       
00352     std::cout << " " << std::endl;
00353   }
00354 }
00355 
00356 void EcalDigiDisplay::readPNDigis(edm::Handle<EcalPnDiodeDigiCollection> PNs, int Mode) {
00357 
00358   int pnDigiCounter = 0;
00359 
00360   //Loop over PN digis
00361   for ( EcalPnDiodeDigiCollection::const_iterator pnItr = PNs->begin(); pnItr != PNs->end(); ++pnItr ) {
00362     EcalPnDiodeDetId pnDetId = EcalPnDiodeDetId((*pnItr).id());
00363     //Make sure that we look at the requested place
00364     int FEDid = pnDetId.iDCCId() + 600;
00365     std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
00366     if (fedIter ==  requestedFeds_.end()) continue;
00367     int pnNum = (*pnItr).id().iPnId();
00368     
00369     if ( Mode == 1) {
00370       edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDisplay  digi PN collection.  Size: " << PNs->size();
00371       edm::LogInfo("EcalDigiDisplay") << "                       [EcalDigiDisplay]  dumping first " << listPns[0] << " PNs ";
00372       
00373       if ( (pnDigiCounter++) >= listPns[0] ) break;
00374     } else if ( Mode == 2) {
00375       edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDisplay  digi PN collection.  Size: " << PNs->size();
00376       
00377       // Check that we look at PN from the given list
00378       std::vector<int>::iterator pnIter;
00379       pnIter = find(listPns.begin(), listPns.end(), pnNum);
00380       if (pnIter == listPns.end())  continue; 
00381     } else {
00382       edm::LogError("EcalDigiDisplay")<< "[EcalDigiDisplay] parameter mode set to: " << Mode
00383                                       << ". Only mode 1 and 2 are allowed. Returning...";
00384       inputIsOk = false;
00385       return;
00386     }
00387     
00388     std::cout << "DCCID: " << pnDetId.iDCCId() << std::endl;
00389     std::cout << "\nPN num: " << (*pnItr).id().iPnId();
00390     for ( int samId=0; samId < (*pnItr).size() ; samId++ ) {
00391       if (!(samId%3)  )  std::cout << "\n\t";
00392       std::cout <<  "sId: " << (samId+1) << " "
00393                 << (*pnItr).sample(samId) 
00394                 << "\t";
00395     }
00396   }
00397 }
00398 
00399 //===================================================
00400 void EcalDigiDisplay::endJob() {
00401 //==================================================
00402   edm::LogInfo("EcalDigiDisplay") << "DONE!.... " ;
00403 }
00404 
00405