CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/EcalEndcapMonitorTasks/src/EEStatusFlagsTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EEStatusFlagsTask.cc
00003  *
00004  * $Date: 2012/04/27 13:46:16 $
00005  * $Revision: 1.43 $
00006  * \author G. Della Ricca
00007  *
00008 */
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 #include <vector>
00013 
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "DQMServices/Core/interface/MonitorElement.h"
00018 
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 
00021 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00022 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
00023 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00024 
00025 #include "DQM/EcalCommon/interface/Numbers.h"
00026 
00027 #include "DQM/EcalEndcapMonitorTasks/interface/EEStatusFlagsTask.h"
00028 
00029 EEStatusFlagsTask::EEStatusFlagsTask(const edm::ParameterSet& ps){
00030 
00031   init_ = false;
00032 
00033   dqmStore_ = edm::Service<DQMStore>().operator->();
00034 
00035   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00036 
00037   subfolder_ = ps.getUntrackedParameter<std::string>("subfolder", "");
00038 
00039   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00040 
00041   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00042 
00043   EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
00044 
00045   for (int i = 0; i < 18; i++) {
00046     meEvtType_[i] = 0;
00047 
00048     meFEchErrors_[i][0] = 0;
00049     meFEchErrors_[i][1] = 0;
00050     meFEchErrors_[i][2] = 0;
00051   }
00052 
00053   meFEchErrorsByLumi_ = 0;
00054 
00055 }
00056 
00057 EEStatusFlagsTask::~EEStatusFlagsTask(){
00058 
00059 }
00060 
00061 void EEStatusFlagsTask::beginJob(void){
00062 
00063   ievt_ = 0;
00064 
00065   if ( dqmStore_ ) {
00066     dqmStore_->setCurrentFolder(prefixME_ + "/EEStatusFlagsTask");
00067     if(subfolder_.size())
00068       dqmStore_->setCurrentFolder(prefixME_ + "/EEStatusFlagsTask/" + subfolder_);
00069     dqmStore_->rmdir(prefixME_ + "/EEStatusFlagsTask");
00070   }
00071 
00072 }
00073 
00074 void EEStatusFlagsTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const  edm::EventSetup& iSetup) {
00075 
00076   if ( meFEchErrorsByLumi_ ) meFEchErrorsByLumi_->Reset();
00077 
00078 }
00079 
00080 void EEStatusFlagsTask::endLuminosityBlock(const edm::LuminosityBlock&  lumiBlock, const  edm::EventSetup& iSetup) {
00081 }
00082 
00083 void EEStatusFlagsTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00084 
00085   Numbers::initGeometry(c, false);
00086 
00087   if ( ! mergeRuns_ ) this->reset();
00088 
00089 }
00090 
00091 void EEStatusFlagsTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00092 
00093 }
00094 
00095 void EEStatusFlagsTask::reset(void) {
00096 
00097   for (int i = 0; i < 18; i++) {
00098     if ( meEvtType_[i] ) meEvtType_[i]->Reset();
00099 
00100     if ( meFEchErrors_[i][0] ) meFEchErrors_[i][0]->Reset();
00101     if ( meFEchErrors_[i][1] ) meFEchErrors_[i][1]->Reset();
00102     if ( meFEchErrors_[i][2] ) meFEchErrors_[i][2]->Reset();
00103   }
00104   if ( meFEchErrorsByLumi_ ) meFEchErrorsByLumi_->Reset();
00105 
00106 }
00107 
00108 void EEStatusFlagsTask::setup(void){
00109 
00110   init_ = true;
00111 
00112   std::string name;
00113   std::string dir;
00114 
00115   if ( dqmStore_ ) {
00116     dir = prefixME_ + "/EEStatusFlagsTask";
00117     if(subfolder_.size())
00118       dir = prefixME_ + "/EEStatusFlagsTask/" + subfolder_;
00119 
00120     dqmStore_->setCurrentFolder(dir);
00121 
00122     dqmStore_->setCurrentFolder(dir + "/EvtType");
00123     for (int i = 0; i < 18; i++) {
00124       name = "EESFT EVTTYPE " + Numbers::sEE(i+1);
00125       meEvtType_[i] = dqmStore_->book1D(name, name, 31, -1., 30.);
00126       meEvtType_[i]->setBinLabel(1, "UNKNOWN", 1);
00127       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::COSMIC, "COSMIC", 1);
00128       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::BEAMH4, "BEAMH4", 1);
00129       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::BEAMH2, "BEAMH2", 1);
00130       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::MTCC, "MTCC", 1);
00131       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LASER_STD, "LASER_STD", 1);
00132       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LASER_POWER_SCAN, "LASER_POWER_SCAN", 1);
00133       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LASER_DELAY_SCAN, "LASER_DELAY_SCAN", 1);
00134       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM, "TESTPULSE_SCAN_MEM", 1);
00135       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_MGPA, "TESTPULSE_MGPA", 1);
00136       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_STD, "PEDESTAL_STD", 1);
00137       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN, "PEDESTAL_OFFSET_SCAN", 1);
00138       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN, "PEDESTAL_25NS_SCAN", 1);
00139       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LED_STD, "LED_STD", 1);
00140       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_GLOBAL, "PHYSICS_GLOBAL", 1);
00141       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_GLOBAL, "COSMICS_GLOBAL", 1);
00142       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::HALO_GLOBAL, "HALO_GLOBAL", 1);
00143       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LASER_GAP, "LASER_GAP", 1);
00144       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_GAP, "TESTPULSE_GAP");
00145       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_GAP, "PEDESTAL_GAP");
00146       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LED_GAP, "LED_GAP", 1);
00147       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_LOCAL, "PHYSICS_LOCAL", 1);
00148       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_LOCAL, "COSMICS_LOCAL", 1);
00149       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::HALO_LOCAL, "HALO_LOCAL", 1);
00150       dqmStore_->tag(meEvtType_[i], i+1);
00151     }
00152 
00153     dqmStore_->setCurrentFolder(dir + "/FEStatus");
00154     for (int i = 0; i < 18; i++) {
00155       name = "EESFT front-end status " + Numbers::sEE(i+1);
00156       meFEchErrors_[i][0] = dqmStore_->book2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50.);
00157       meFEchErrors_[i][0]->setAxisTitle("ix", 1);
00158       if ( i+1 >= 1 && i+1 <= 9 ) meFEchErrors_[i][0]->setAxisTitle("101-ix", 1);
00159       meFEchErrors_[i][0]->setAxisTitle("iy", 2);
00160       dqmStore_->tag(meFEchErrors_[i][0], i+1);
00161 
00162       name = "EESFT MEM front-end status " + Numbers::sEE(i+1);
00163       meFEchErrors_[i][1] = dqmStore_->book2D(name, name, 2, 0., 2., 1, 0., 1.);
00164       meFEchErrors_[i][1]->setAxisTitle("pseudo-strip", 1);
00165       meFEchErrors_[i][1]->setAxisTitle("channel", 2);
00166       dqmStore_->tag(meFEchErrors_[i][1], i+1);
00167 
00168       name = "EESFT front-end status bits " + Numbers::sEE(i+1);
00169       meFEchErrors_[i][2] = dqmStore_->book1D(name, name, 16, 0., 16.);
00170       meFEchErrors_[i][2]->setBinLabel(1+0, "ACTIVE", 1);
00171       meFEchErrors_[i][2]->setBinLabel(1+1, "DISABLED", 1);
00172       meFEchErrors_[i][2]->setBinLabel(1+2, "TIMEOUT", 1);
00173       meFEchErrors_[i][2]->setBinLabel(1+3, "HEADER", 1);
00174       meFEchErrors_[i][2]->setBinLabel(1+4, "CHANNEL ID", 1);
00175       meFEchErrors_[i][2]->setBinLabel(1+5, "LINK", 1);
00176       meFEchErrors_[i][2]->setBinLabel(1+6, "BLOCKSIZE", 1);
00177       meFEchErrors_[i][2]->setBinLabel(1+7, "SUPPRESSED", 1);
00178       meFEchErrors_[i][2]->setBinLabel(1+8, "FORCED FS", 1);
00179       meFEchErrors_[i][2]->setBinLabel(1+9, "L1A SYNC", 1);
00180       meFEchErrors_[i][2]->setBinLabel(1+10, "BX SYNC", 1);
00181       meFEchErrors_[i][2]->setBinLabel(1+11, "L1A+BX SYNC", 1);
00182       meFEchErrors_[i][2]->setBinLabel(1+12, "FIFO FULL+L1A", 1);
00183       meFEchErrors_[i][2]->setBinLabel(1+13, "H PARITY", 1);
00184       meFEchErrors_[i][2]->setBinLabel(1+14, "V PARITY", 1);
00185       meFEchErrors_[i][2]->setBinLabel(1+15, "FORCED ZS", 1);
00186       dqmStore_->tag(meFEchErrors_[i][2], i+1);
00187     }
00188 
00189     // checking the number of front-end errors in each DCC for each lumi
00190     // tower error is weighted by 1/34
00191     // bin 0 contains the number of processed events in the lumi (for normalization)
00192     name = "EESFT weighted frontend errors by lumi";
00193     meFEchErrorsByLumi_ = dqmStore_->book1D(name, name, 18, 1., 19.);
00194     meFEchErrorsByLumi_->setLumiFlag();
00195     for (int i = 0; i < 18; i++) {
00196       meFEchErrorsByLumi_->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
00197     }
00198 
00199   }
00200 
00201 }
00202 
00203 void EEStatusFlagsTask::cleanup(void){
00204 
00205   if ( ! init_ ) return;
00206 
00207   if ( dqmStore_ ) {
00208     std::string dir = prefixME_ + "/EEStatusFlagsTask";
00209     if(subfolder_.size())
00210       dir = prefixME_ + "/EEStatusFlagsTask/" + subfolder_;
00211 
00212     dqmStore_->setCurrentFolder(dir + "");
00213 
00214     dqmStore_->setCurrentFolder(dir + "/EvtType");
00215     for (int i = 0; i < 18; i++) {
00216       if ( meEvtType_[i] ) dqmStore_->removeElement( meEvtType_[i]->getName() );
00217       meEvtType_[i] = 0;
00218     }
00219 
00220     dqmStore_->setCurrentFolder(dir + "/FEStatus");
00221     for (int i = 0; i < 18; i++) {
00222       if ( meFEchErrors_[i][0] ) dqmStore_->removeElement( meFEchErrors_[i][0]->getName() );
00223       meFEchErrors_[i][0] = 0;
00224       if ( meFEchErrors_[i][1] ) dqmStore_->removeElement( meFEchErrors_[i][1]->getName() );
00225       meFEchErrors_[i][1] = 0;
00226       if ( meFEchErrors_[i][2] ) dqmStore_->removeElement( meFEchErrors_[i][2]->getName() );
00227       meFEchErrors_[i][2] = 0;
00228     }
00229 
00230     if ( meFEchErrorsByLumi_ ) dqmStore_->removeElement( meFEchErrorsByLumi_->getName() );
00231     meFEchErrorsByLumi_ = 0;
00232 
00233   }
00234 
00235   init_ = false;
00236 
00237 }
00238 
00239 void EEStatusFlagsTask::endJob(void){
00240 
00241   edm::LogInfo("EEStatusFlagsTask") << "analyzed " << ievt_ << " events";
00242 
00243   if ( enableCleanup_ ) this->cleanup();
00244 
00245 }
00246 
00247 void EEStatusFlagsTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00248 
00249   if ( ! init_ ) this->setup();
00250 
00251   ievt_++;
00252 
00253   // fill bin 0 with number of events in the lumi
00254   if ( meFEchErrorsByLumi_ ) meFEchErrorsByLumi_->Fill(0.);
00255 
00256   edm::Handle<EcalRawDataCollection> dcchs;
00257 
00258   if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00259 
00260     for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00261 
00262       if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
00263 
00264       int ism = Numbers::iSM( *dcchItr, EcalEndcap );
00265       float xism = ism + 0.5;
00266 
00267       if ( meEvtType_[ism-1] ) meEvtType_[ism-1]->Fill(dcchItr->getRunType()+0.5);
00268 
00269       const std::vector<short> status = dcchItr->getFEStatus();
00270 
00271       for ( unsigned int itt=1; itt<=status.size(); itt++ ) {
00272 
00273         if ( itt > 70 ) continue;
00274 
00275         if ( itt >= 42 && itt <= 68 ) continue;
00276 
00277         if ( ( ism == 8 || ism == 17 ) && ( itt >= 18 && itt <= 24 ) ) continue;
00278 
00279         if ( itt >= 1 && itt <= 41 ) {
00280 
00281           std::vector<DetId>* crystals = Numbers::crystals( dcchItr->id(), itt );
00282 
00283           for ( unsigned int i=0; i<crystals->size(); i++ ) {
00284 
00285           EEDetId id = (*crystals)[i];
00286 
00287           int ix = id.ix();
00288           int iy = id.iy();
00289 
00290           if ( ism >= 1 && ism <= 9 ) ix = 101 - ix;
00291 
00292           float xix = ix - 0.5;
00293           float xiy = iy - 0.5;
00294 
00295           if ( ! ( status[itt-1] == 0 || status[itt-1] == 1 || status[itt-1] == 7 || status[itt-1] == 8 || status[itt-1] == 12 || status[itt-1] == 15 ) ) {
00296             if ( meFEchErrors_[ism-1][0] ) meFEchErrors_[ism-1][0]->Fill(xix, xiy);
00297             if ( meFEchErrorsByLumi_ ) meFEchErrorsByLumi_->Fill(xism, 1./34./crystals->size());
00298           }
00299 
00300           }
00301 
00302         } else if ( itt == 69 || itt == 70 ) {
00303 
00304           if ( ! ( status[itt-1] == 0 || status[itt-1] == 1 || status[itt-1] == 7 || status[itt-1] == 8 || status[itt-1] == 12 || status[itt-1] == 15 ) ) {
00305             if ( meFEchErrors_[ism-1][1] ) meFEchErrors_[ism-1][1]->Fill(itt-68-0.5, 0);
00306           }
00307 
00308         }
00309 
00310         if ( meFEchErrors_[ism-1][2] ) meFEchErrors_[ism-1][2]->Fill(status[itt-1]+0.5);
00311 
00312       }
00313 
00314     }
00315 
00316   } else {
00317 
00318     edm::LogWarning("EEStatusFlagsTask") << EcalRawDataCollection_ << " not available";
00319 
00320   }
00321 
00322 }
00323