CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/EcalBarrelMonitorTasks/src/EBHltTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBHltTask.cc
00003  *
00004  * $Date: 2010/08/11 14:57:34 $
00005  * $Revision: 1.16 $
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   char histo[200];
00108 
00109   if ( dqmStore_ ) {
00110     dqmStore_->setCurrentFolder(prefixME_ + "/" + folderName_);
00111 
00112     sprintf(histo, "FEDEntries");
00113     meEBFedsOccupancy_ = dqmStore_->book1D(histo, histo, 36, 610, 646);
00114 
00115     sprintf(histo, "FEDFatal");
00116     meEBFedsSizeErrors_ = dqmStore_->book1D(histo, histo, 36, 610, 646);
00117 
00118     sprintf(histo, "FEDNonFatal");
00119     meEBFedsIntegrityErrors_ = dqmStore_->book1D(histo, histo, 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 //    edm::LogWarning("EBHltTask") << EBDetIdCollection0_ << " not available";
00182 
00183   }
00184 
00185   edm::Handle<FEDRawDataCollection> allFedRawData;
00186 
00187   if ( e.getByLabel(FEDRawDataCollection_, allFedRawData) ) {
00188 
00189     for ( int ism=1; ism<=36; ism++ ) {
00190 
00191       const FEDRawData& fedData = allFedRawData->FEDData( EBFirstFED + ism - 1 );
00192 
00193       int length = fedData.size()/sizeof(uint64_t);
00194 
00195       if ( length > 0 ) {
00196 
00197         if ( meEBFedsOccupancy_ ) meEBFedsOccupancy_->Fill( EBFirstFED + ism - 1 );
00198 
00199         uint64_t * pData = (uint64_t *)(fedData.data());
00200         uint64_t * fedTrailer = pData + (length - 1);
00201         bool crcError = (*fedTrailer >> 2 ) & 0x1;
00202 
00203         if (crcError) FedsSizeErrors[ism-1]++;
00204 
00205       }
00206 
00207     }
00208 
00209   } else {
00210     edm::LogWarning("EBHltTask") << FEDRawDataCollection_ << " not available";
00211   }
00212 
00213 
00214   for( int ism=1; ism<=36; ism++ ) {
00215 
00216     if ( FedsSizeErrors[ism-1] != 0 ) {
00217 
00218       if ( meEBFedsSizeErrors_ ) meEBFedsSizeErrors_->Fill( EBFirstFED + ism - 1 );
00219 
00220     }
00221 
00222   }
00223 
00224 
00225   // Integrity errors
00226   edm::Handle<EBDetIdCollection> ids1;
00227 
00228   if ( e.getByLabel(EBDetIdCollection1_, ids1) ) {
00229 
00230     for ( EBDetIdCollection::const_iterator idItr = ids1->begin(); idItr != ids1->end(); ++idItr ) {
00231 
00232       int ism = iSM( *idItr );
00233 
00234       if( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00235 
00236     }
00237 
00238   } else {
00239 
00240     edm::LogWarning("EBHltTask") << EBDetIdCollection1_ << " not available";
00241 
00242   }
00243 
00244   edm::Handle<EBDetIdCollection> ids2;
00245 
00246   if ( e.getByLabel(EBDetIdCollection2_, ids2) ) {
00247 
00248     for ( EBDetIdCollection::const_iterator idItr = ids2->begin(); idItr != ids2->end(); ++idItr ) {
00249 
00250       int ism = iSM( *idItr );
00251 
00252       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00253 
00254     }
00255 
00256   } else {
00257 
00258     edm::LogWarning("EBHltTask") << EBDetIdCollection2_ << " not available";
00259 
00260   }
00261 
00262   edm::Handle<EBDetIdCollection> ids3;
00263 
00264   if ( e.getByLabel(EBDetIdCollection3_, ids3) ) {
00265 
00266     for ( EBDetIdCollection::const_iterator idItr = ids3->begin(); idItr != ids3->end(); ++idItr ) {
00267 
00268       int ism = iSM( *idItr );
00269 
00270       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00271 
00272     }
00273 
00274   } else {
00275 
00276     edm::LogWarning("EBHltTask") << EBDetIdCollection3_ << " not available";
00277 
00278   }
00279 
00280   edm::Handle<EcalElectronicsIdCollection> ids4;
00281 
00282   if ( e.getByLabel(EcalElectronicsIdCollection1_, ids4) ) {
00283 
00284     for ( EcalElectronicsIdCollection::const_iterator idItr = ids4->begin(); idItr != ids4->end(); ++idItr ) {
00285 
00286       if ( subDet( *idItr ) != EcalBarrel ) continue;
00287 
00288       int ism = iSM( *idItr );
00289 
00290       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./68.);
00291 
00292     }
00293 
00294   } else {
00295 
00296     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection1_ << " not available";
00297 
00298   }
00299 
00300   edm::Handle<EcalElectronicsIdCollection> ids5;
00301 
00302   if ( e.getByLabel(EcalElectronicsIdCollection2_, ids5) ) {
00303 
00304     for ( EcalElectronicsIdCollection::const_iterator idItr = ids5->begin(); idItr != ids5->end(); ++idItr ) {
00305 
00306       if ( subDet( *idItr ) != EcalBarrel ) continue;
00307 
00308       int ism = iSM( *idItr );
00309 
00310       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00311 
00312     }
00313 
00314   } else {
00315 
00316     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection2_ << " not available";
00317 
00318   }
00319 
00320   edm::Handle<EcalElectronicsIdCollection> ids6;
00321 
00322   if ( e.getByLabel(EcalElectronicsIdCollection3_, ids6) ) {
00323 
00324     for ( EcalElectronicsIdCollection::const_iterator idItr = ids6->begin(); idItr != ids6->end(); ++idItr ) {
00325 
00326       if ( subDet( *idItr ) != EcalBarrel ) continue;
00327 
00328       int ism = iSM( *idItr );
00329 
00330       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./68.);
00331 
00332     }
00333 
00334   } else {
00335 
00336     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection3_ << " not available";
00337 
00338   }
00339 
00340   edm::Handle<EcalElectronicsIdCollection> ids7;
00341 
00342   if ( e.getByLabel(EcalElectronicsIdCollection4_, ids7) ) {
00343 
00344     for ( EcalElectronicsIdCollection::const_iterator idItr = ids7->begin(); idItr != ids7->end(); ++idItr ) {
00345 
00346       if ( subDet( *idItr ) != EcalBarrel ) continue;
00347 
00348       int ism = iSM( *idItr );
00349 
00350       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00351 
00352     }
00353 
00354   } else {
00355 
00356     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection4_ << " not available";
00357 
00358   }
00359 
00360   edm::Handle<EcalElectronicsIdCollection> ids8;
00361 
00362   if ( e.getByLabel(EcalElectronicsIdCollection5_, ids8) ) {
00363 
00364     for ( EcalElectronicsIdCollection::const_iterator idItr = ids8->begin(); idItr != ids8->end(); ++idItr ) {
00365 
00366       if ( subDet( *idItr ) != EcalBarrel ) continue;
00367 
00368       int ism = iSM( *idItr );
00369 
00370       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00371 
00372     }
00373 
00374   } else {
00375 
00376     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection5_ << " not available";
00377 
00378   }
00379 
00380   edm::Handle<EcalElectronicsIdCollection> ids9;
00381 
00382   if ( e.getByLabel(EcalElectronicsIdCollection6_, ids9) ) {
00383 
00384     for ( EcalElectronicsIdCollection::const_iterator idItr = ids9->begin(); idItr != ids9->end(); ++idItr ) {
00385 
00386       if ( subDet( *idItr ) != EcalBarrel ) continue;
00387 
00388       int ism = iSM( *idItr );
00389 
00390       if ( ism > -1 ) meEBFedsIntegrityErrors_->Fill( EBFirstFED + ism - 1, 1./1700.);
00391 
00392     }
00393 
00394   } else {
00395 
00396     edm::LogWarning("EBHltTask") << EcalElectronicsIdCollection6_ << " not available";
00397 
00398   }
00399 
00400 }
00401 
00402 //-------------------------------------------------------------------------
00403 
00404 void EBHltTask::initGeometry( const edm::EventSetup& setup ) {
00405 
00406   if( initGeometry_ ) return;
00407 
00408   initGeometry_ = true;
00409 
00410   edm::ESHandle< EcalElectronicsMapping > handle;
00411   setup.get< EcalMappingRcd >().get(handle);
00412   map = handle.product();
00413 
00414   if( ! map ) edm::LogWarning("EBHltTask") << "EcalElectronicsMapping not available";
00415 
00416 }
00417 
00418 int EBHltTask::iSM( const EBDetId& id ) {
00419 
00420   if( ! map ) return -1;
00421 
00422   EcalElectronicsId eid = map->getElectronicsId(id);
00423   int idcc = eid.dccId();
00424 
00425   // EB-/EB+
00426   if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00427 
00428   edm::LogWarning("EBHltTask") << "Wrong DCC id: dcc = " << idcc;
00429   return -1;
00430 
00431 }
00432 
00433 int EBHltTask::iSM( const EcalElectronicsId& id ) {
00434 
00435   int idcc = id.dccId();
00436 
00437   // EB-/EB+
00438   if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00439 
00440   edm::LogWarning("EBHltTask") << "Wrong DCC id: dcc = " << idcc;
00441   return -1;
00442 
00443 }
00444