CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DQM/EcalBarrelMonitorTasks/src/EBHltTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBHltTask.cc
00003  *
00004  * $Date: 2012/04/27 13:46:02 $
00005  * $Revision: 1.21 $
00006  * \author G. Della Ricca
00007  *
00008 */
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00017 
00018 #include "DQMServices/Core/interface/MonitorElement.h"
00019 
00020 #include "DQMServices/Core/interface/DQMStore.h"
00021 
00022 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00023 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00024 
00025 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00026 
00027 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00028 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
00029 
00030 #include "DQM/EcalBarrelMonitorTasks/interface/EBHltTask.h"
00031 
00032 EBHltTask::EBHltTask(const edm::ParameterSet& ps){
00033 
00034   init_ = false;
00035 
00036   initGeometry_ = false;
00037 
00038   dqmStore_ = edm::Service<DQMStore>().operator->();
00039 
00040   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00041 
00042   folderName_ = ps.getUntrackedParameter<std::string>("folderName", "FEDIntegrity");
00043 
00044   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00045 
00046   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00047 
00048   EBDetIdCollection0_ =  ps.getParameter<edm::InputTag>("EBDetIdCollection0");
00049   EBDetIdCollection1_ =  ps.getParameter<edm::InputTag>("EBDetIdCollection1");
00050   EBDetIdCollection2_ =  ps.getParameter<edm::InputTag>("EBDetIdCollection2");
00051   EBDetIdCollection3_ =  ps.getParameter<edm::InputTag>("EBDetIdCollection3");
00052   EcalElectronicsIdCollection1_ = ps.getParameter<edm::InputTag>("EcalElectronicsIdCollection1");
00053   EcalElectronicsIdCollection2_ = ps.getParameter<edm::InputTag>("EcalElectronicsIdCollection2");
00054   EcalElectronicsIdCollection3_ = ps.getParameter<edm::InputTag>("EcalElectronicsIdCollection3");
00055   EcalElectronicsIdCollection4_ = ps.getParameter<edm::InputTag>("EcalElectronicsIdCollection4");
00056   EcalElectronicsIdCollection5_ = ps.getParameter<edm::InputTag>("EcalElectronicsIdCollection5");
00057   EcalElectronicsIdCollection6_ = ps.getParameter<edm::InputTag>("EcalElectronicsIdCollection6");
00058   FEDRawDataCollection_ = ps.getParameter<edm::InputTag>("FEDRawDataCollection");
00059 
00060   meEBFedsOccupancy_ = 0;
00061   meEBFedsSizeErrors_ = 0;
00062   meEBFedsIntegrityErrors_ = 0;
00063 
00064   map = 0;
00065 
00066 }
00067 
00068 EBHltTask::~EBHltTask(){
00069 
00070 }
00071 
00072 void EBHltTask::beginJob(void){
00073 
00074   ievt_ = 0;
00075 
00076   if ( dqmStore_ ) {
00077     dqmStore_->setCurrentFolder(prefixME_ + "/" + folderName_);
00078     dqmStore_->rmdir(prefixME_ + "/" + folderName_);
00079   }
00080 
00081 }
00082 
00083 void EBHltTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00084 
00085   initGeometry(c);
00086 
00087   if ( ! mergeRuns_ ) this->reset();
00088 
00089 }
00090 
00091 void EBHltTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00092 
00093 }
00094 
00095 void EBHltTask::reset(void) {
00096 
00097   if ( meEBFedsOccupancy_ ) meEBFedsOccupancy_->Reset();
00098   if ( meEBFedsSizeErrors_ ) meEBFedsSizeErrors_->Reset();
00099   if ( meEBFedsIntegrityErrors_ ) meEBFedsIntegrityErrors_->Reset();
00100 
00101 }
00102 
00103 void EBHltTask::setup(void){
00104 
00105   init_ = true;
00106 
00107   std::string name;
00108 
00109   if ( dqmStore_ ) {
00110     dqmStore_->setCurrentFolder(prefixME_ + "/" + folderName_);
00111 
00112     name = "FEDEntries";
00113     meEBFedsOccupancy_ = dqmStore_->book1D(name, name, 36, 610, 646);
00114 
00115     name = "FEDFatal";
00116     meEBFedsSizeErrors_ = dqmStore_->book1D(name, name, 36, 610, 646);
00117 
00118     name = "FEDNonFatal";
00119     meEBFedsIntegrityErrors_ = dqmStore_->book1D(name, name, 36, 610, 646);
00120 
00121   }
00122 
00123 }
00124 
00125 void EBHltTask::cleanup(void){
00126 
00127   if ( ! init_ ) return;
00128 
00129   if ( dqmStore_ ) {
00130     dqmStore_->setCurrentFolder(prefixME_ + "/" + folderName_);
00131 
00132     if ( meEBFedsOccupancy_ ) dqmStore_->removeElement( meEBFedsOccupancy_->getName() );
00133     meEBFedsOccupancy_ = 0;
00134 
00135     if ( meEBFedsSizeErrors_ ) dqmStore_->removeElement( meEBFedsSizeErrors_->getName() );
00136     meEBFedsSizeErrors_ = 0;
00137 
00138     if ( meEBFedsIntegrityErrors_ ) dqmStore_->removeElement( meEBFedsIntegrityErrors_->getName() );
00139     meEBFedsIntegrityErrors_ = 0;
00140 
00141   }
00142 
00143   init_ = false;
00144 
00145 }
00146 
00147 void EBHltTask::endJob(void){
00148 
00149   edm::LogInfo("EBHltTask") << "analyzed " << ievt_ << " events";
00150 
00151   if ( enableCleanup_ ) this->cleanup();
00152 
00153 }
00154 
00155 void EBHltTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00156 
00157   if ( ! init_ ) this->setup();
00158 
00159   ievt_++;
00160 
00161   // ECAL barrel FEDs
00162   int EBFirstFED=610;
00163 
00164   int FedsSizeErrors[36];
00165   for ( int i=0; i<36; i++ ) FedsSizeErrors[i]=0;
00166 
00167   edm::Handle<EBDetIdCollection> ids0;
00168 
00169   if ( e.getByLabel(EBDetIdCollection0_, ids0) ) {
00170 
00171     for ( EBDetIdCollection::const_iterator idItr = ids0->begin(); idItr != ids0->end(); ++idItr ) {
00172 
00173       int ism = iSM( *idItr );
00174 
00175       if ( ism > -1 ) FedsSizeErrors[ism-1]++;
00176 
00177     }
00178 
00179   } else {
00180 
00181   }
00182 
00183   edm::Handle<FEDRawDataCollection> allFedRawData;
00184 
00185   if ( e.getByLabel(FEDRawDataCollection_, allFedRawData) ) {
00186 
00187     for ( int ism=1; ism<=36; ism++ ) {
00188 
00189       const FEDRawData& fedData = allFedRawData->FEDData( EBFirstFED + ism - 1 );
00190 
00191       int length = fedData.size()/sizeof(uint64_t);
00192 
00193       if ( length > 0 ) {
00194 
00195         if ( meEBFedsOccupancy_ ) meEBFedsOccupancy_->Fill( EBFirstFED + ism - 1 );
00196 
00197         uint64_t * pData = (uint64_t *)(fedData.data());
00198         uint64_t * fedTrailer = pData + (length - 1);
00199         bool crcError = (*fedTrailer >> 2 ) & 0x1;
00200 
00201         if (crcError) FedsSizeErrors[ism-1]++;
00202 
00203       }
00204 
00205     }
00206 
00207   } else {
00208     edm::LogWarning("EBHltTask") << FEDRawDataCollection_ << " not available";
00209   }
00210 
00211 
00212   for( int ism=1; ism<=36; ism++ ) {
00213 
00214     if ( FedsSizeErrors[ism-1] != 0 ) {
00215 
00216       if ( meEBFedsSizeErrors_ ) meEBFedsSizeErrors_->Fill( EBFirstFED + ism - 1 );
00217 
00218     }
00219 
00220   }
00221 
00222 
00223   // Integrity errors
00224   edm::Handle<EBDetIdCollection> ids1;
00225 
00226   if ( e.getByLabel(EBDetIdCollection1_, ids1) ) {
00227 
00228     for ( EBDetIdCollection::const_iterator idItr = ids1->begin(); idItr != ids1->end(); ++idItr ) {
00229 
00230       int ism = iSM( *idItr );
00231 
00232       if( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00233 
00234     }
00235 
00236   } else {
00237 
00238     edm::LogWarning("EBHltTask") << EBDetIdCollection1_ << " not available";
00239 
00240   }
00241 
00242   edm::Handle<EBDetIdCollection> ids2;
00243 
00244   if ( e.getByLabel(EBDetIdCollection2_, ids2) ) {
00245 
00246     for ( EBDetIdCollection::const_iterator idItr = ids2->begin(); idItr != ids2->end(); ++idItr ) {
00247 
00248       int ism = iSM( *idItr );
00249 
00250       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00251 
00252     }
00253 
00254   } else {
00255 
00256     edm::LogWarning("EBHltTask") << EBDetIdCollection2_ << " not available";
00257 
00258   }
00259 
00260   edm::Handle<EBDetIdCollection> ids3;
00261 
00262   if ( e.getByLabel(EBDetIdCollection3_, ids3) ) {
00263 
00264     for ( EBDetIdCollection::const_iterator idItr = ids3->begin(); idItr != ids3->end(); ++idItr ) {
00265 
00266       int ism = iSM( *idItr );
00267 
00268       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00269 
00270     }
00271 
00272   } else {
00273 
00274     edm::LogWarning("EBHltTask") << EBDetIdCollection3_ << " not available";
00275 
00276   }
00277 
00278   edm::Handle<EcalElectronicsIdCollection> ids4;
00279 
00280   if ( e.getByLabel(EcalElectronicsIdCollection1_, ids4) ) {
00281 
00282     for ( EcalElectronicsIdCollection::const_iterator idItr = ids4->begin(); idItr != ids4->end(); ++idItr ) {
00283 
00284       if ( subDet( *idItr ) != EcalBarrel ) continue;
00285 
00286       int ism = iSM( *idItr );
00287 
00288       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./68.);
00289 
00290     }
00291 
00292   } else {
00293 
00294     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection1_ << " not available";
00295 
00296   }
00297 
00298   edm::Handle<EcalElectronicsIdCollection> ids5;
00299 
00300   if ( e.getByLabel(EcalElectronicsIdCollection2_, ids5) ) {
00301 
00302     for ( EcalElectronicsIdCollection::const_iterator idItr = ids5->begin(); idItr != ids5->end(); ++idItr ) {
00303 
00304       if ( subDet( *idItr ) != EcalBarrel ) continue;
00305 
00306       int ism = iSM( *idItr );
00307 
00308       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00309 
00310     }
00311 
00312   } else {
00313 
00314     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection2_ << " not available";
00315 
00316   }
00317 
00318   edm::Handle<EcalElectronicsIdCollection> ids6;
00319 
00320   if ( e.getByLabel(EcalElectronicsIdCollection3_, ids6) ) {
00321 
00322     for ( EcalElectronicsIdCollection::const_iterator idItr = ids6->begin(); idItr != ids6->end(); ++idItr ) {
00323 
00324       if ( subDet( *idItr ) != EcalBarrel ) continue;
00325 
00326       int ism = iSM( *idItr );
00327 
00328       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./68.);
00329 
00330     }
00331 
00332   } else {
00333 
00334     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection3_ << " not available";
00335 
00336   }
00337 
00338   edm::Handle<EcalElectronicsIdCollection> ids7;
00339 
00340   if ( e.getByLabel(EcalElectronicsIdCollection4_, ids7) ) {
00341 
00342     for ( EcalElectronicsIdCollection::const_iterator idItr = ids7->begin(); idItr != ids7->end(); ++idItr ) {
00343 
00344       if ( subDet( *idItr ) != EcalBarrel ) continue;
00345 
00346       int ism = iSM( *idItr );
00347 
00348       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00349 
00350     }
00351 
00352   } else {
00353 
00354     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection4_ << " not available";
00355 
00356   }
00357 
00358   edm::Handle<EcalElectronicsIdCollection> ids8;
00359 
00360   if ( e.getByLabel(EcalElectronicsIdCollection5_, ids8) ) {
00361 
00362     for ( EcalElectronicsIdCollection::const_iterator idItr = ids8->begin(); idItr != ids8->end(); ++idItr ) {
00363 
00364       if ( subDet( *idItr ) != EcalBarrel ) continue;
00365 
00366       int ism = iSM( *idItr );
00367 
00368       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00369 
00370     }
00371 
00372   } else {
00373 
00374     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection5_ << " not available";
00375 
00376   }
00377 
00378   edm::Handle<EcalElectronicsIdCollection> ids9;
00379 
00380   if ( e.getByLabel(EcalElectronicsIdCollection6_, ids9) ) {
00381 
00382     for ( EcalElectronicsIdCollection::const_iterator idItr = ids9->begin(); idItr != ids9->end(); ++idItr ) {
00383 
00384       if ( subDet( *idItr ) != EcalBarrel ) continue;
00385 
00386       int ism = iSM( *idItr );
00387 
00388       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00389 
00390     }
00391 
00392   } else {
00393 
00394     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection6_ << " not available";
00395 
00396   }
00397 
00398 }
00399 
00400 //-------------------------------------------------------------------------
00401 
00402 void EBHltTask::initGeometry( const edm::EventSetup& setup ) {
00403 
00404   if( initGeometry_ ) return;
00405 
00406   initGeometry_ = true;
00407 
00408   edm::ESHandle< EcalElectronicsMapping > handle;
00409   setup.get< EcalMappingRcd >().get(handle);
00410   map = handle.product();
00411 
00412   if( ! map ) edm::LogWarning("EBHltTask") << "EcalElectronicsMapping not available";
00413 
00414 }
00415 
00416 int EBHltTask::iSM( const EBDetId& id ) {
00417 
00418   if( ! map ) return -1;
00419 
00420   EcalElectronicsId eid = map->getElectronicsId(id);
00421   int idcc = eid.dccId();
00422 
00423   // EB-/EB+
00424   if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00425 
00426   edm::LogWarning("EBHltTask") << "Wrong DCC id: dcc = " << idcc;
00427   return -1;
00428 
00429 }
00430 
00431 int EBHltTask::iSM( const EcalElectronicsId& id ) {
00432 
00433   int idcc = id.dccId();
00434 
00435   // EB-/EB+
00436   if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00437 
00438   edm::LogWarning("EBHltTask") << "Wrong DCC id: dcc = " << idcc;
00439   return -1;
00440 
00441 }
00442